Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 05-04-2009, 08:50 PM   #1 (permalink)
SomeYoungGuy
Recruit
 
Join Date: May 2009
Posts: 2
SomeYoungGuy is on a distinguished road
Red face html + js help pls

hi guys, im new here. anyways, im kind of new to html and javascript. been reading a lot of references here and on w3schools.

anyways, i need help, can someone help me make an html and jscript for an age calculator? or an html with the js inside the <head> ? i need the the age calculator to have text boxes for the user to input his/her name, month of birth, day of birth and year of birth, the it will subtract the current system date with the input month + day + year. then the output will say good morning/afternoon/night depending on the system time then the input name "you are ** years old." where ** is the age.
SomeYoungGuy is offline   Reply With Quote
Old 05-05-2009, 12:21 AM   #2 (permalink)
SomeYoungGuy
Recruit
 
Join Date: May 2009
Posts: 2
SomeYoungGuy is on a distinguished road
i found these scripts while googling, can anyone reduce these to make it simpler into just asking for user input of name, month of birth, day of birth, year of birth, a calculate button and a vacant textbox to output the result.

this is the html code:
Code:
<form name="birthday">
Date<select name="day" size="1">
<script language=javascript>
for(var j=1;j<32;j++)
document.write("<option value="+j+">"+j+"</option>");
</script></select> 
Month<select name="month" size="1">
<script language=javascript>
for(var i=1;i<13;i++)
document.write("<option value="+i+">"+i+"</option>");
</script></select> 
Year<select name="year" size="1">
<script language=javascript>
for(var k=startyear;k<endyear;k++)
document.write("<option value="+k+">"+k+"</option>");
</script></select>
<input name="start" onclick="calage()" value="Calculate" type="button"><br>
<input name="age" size="40" value="Result"><br>
You have been living for:<br>
<table style="border:solid green 1px"> <tr><td>In months:</td><td><input name="months" size="30"></td></tr> <tr><td>In days:</td><td><input name="daa" size="30"></td></tr> <tr><td>In hours:</td><td><input name="hours" size="30"></td></tr> <tr><td>In minutes:</td><td><input name="min" size="30"></td></tr> <tr><td colspan=2>Your next birthday will be in:</td></tr> <tr><td colspan=2><input name="nbday" size="40"></td></tr> </table> </form>
and this is the javascript code:
Code:
<script language="javascript">
var startyear = "1950";
var endyear = "2010";
var dat = new Date();

var curday = dat.getDate();
var curmon = dat.getMonth()+1;
var curyear = dat.getFullYear();

function checkleapyear(datea)
{
	if(datea.getYear()%4 == 0)
	{
		if(datea.getYear()% 10 != 0)
		{
			return true;
		}
		else
		{
			if(datea.getYear()% 400 == 0)
				return true;
			else
				return false;
		}
	}
return false;
}
function DaysInMonth(Y, M) {
    with (new Date(Y, M, 1, 12)) {
        setDate(0);
        return getDate();
    }
}
function datediff(date1, date2) {
    var y1 = date1.getFullYear(), m1 = date1.getMonth(), d1 = date1.getDate(),
	 y2 = date2.getFullYear(), m2 = date2.getMonth(), d2 = date2.getDate();

    if (d1 < d2) {
        m1--;
        d1 += DaysInMonth(y2, m2);
    }
    if (m1 < m2) {
        y1--;
        m1 += 12;
    }
    return [y1 - y2, m1 - m2, d1 - d2];
}

function calage()
{
var calday = document.birthday.day.options[document.birthday.day.selectedIndex].value;
var calmon = document.birthday.month.options[document.birthday.month.selectedIndex].value;
var calyear = document.birthday.year.options[document.birthday.year.selectedIndex].value;
	if(curday == "" || curmon=="" || curyear=="" || calday=="" || calmon=="" || calyear=="")
	{
		alert("please fill all the values and click go -");
	}	
	else
	{
		var curd = new Date(curyear,curmon-1,curday);
		var cald = new Date(calyear,calmon-1,calday);
		
		var diff =  Date.UTC(curyear,curmon,curday,0,0,0) - Date.UTC(calyear,calmon,calday,0,0,0);

		var dife = datediff(curd,cald);
		document.birthday.age.value=dife[0]+" years, "+dife[1]+" months, and "+dife[2]+" days";
		var monleft = (dife[0]*12)+dife[1];
		var secleft = diff/1000/60;
		var hrsleft = secleft/60;
		var daysleft = hrsleft/24;
		document.birthday.months.value=monleft+" Month since your birth";	
		document.birthday.daa.value=daysleft+" days since your birth";	
		document.birthday.hours.value=hrsleft+" hours since your birth";
		document.birthday.min.value=secleft+" minutes since your birth";
		var as = parseInt(calyear)+dife[0]+1;
		var diff =  Date.UTC(as,calmon,calday,0,0,0) - Date.UTC(curyear,curmon,curday,0,0,0);
		var datee = diff/1000/60/60/24;
		document.birthday.nbday.value=datee+" days left for your next birthday";	


	}
}
</script>
SomeYoungGuy is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Send HTML page as an HTML email BroadBean PHP 3 02-19-2009 10:14 AM
asp to html tomschute MS Technologies ( ASP, VB, C#, .NET ) 1 01-02-2009 01:24 PM
html vs. php Norton PHP 3 01-03-2008 01:13 AM
Html Css Help NewOldy HTML, XML, Javascript, AJAX 5 06-25-2004 12:51 PM
.ini to HTML DMDrip Standard C, C++ 6 05-22-2004 08:17 AM


All times are GMT -8. The time now is 03:58 PM.


Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0 RC8 ©2007, Crawlability, Inc.





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting