R
Rich
Thanks for the Help in my previous post.
I've been working on this and it's almost what I want.
I want to obtain the user's current age by comparing their date of birth
(user inputs) to the current date.
I know how to get the Current Date but I'm not finding how to calculate the
Current Date minus the User's Birthday.
It would be something like yourage = curdate - bday;
I will then use the results to determine if the User is Over 21 or Under 21.
Any help would be greatly appreciated!
I'm going nuts trying to figure this out.
Is there an Easier Book to learn this stuff other than the "Begining
JavaScript 2nd Edition".
Thanks again for any help. I'm a total novice.
=======================
<HTML>
<HEAD>
<TITLE>Legal Drinking Age </TITLE>
<form>
<input type="button" value="Submit" onClick="legalAge()">
</form>
</HEAD>
<BODY>
<script language="JavaScript" type="text/JavaScript">
var curdate = new Date()
document.write(curdate.getDate())
document.write(".")
document.write(curdate.getMonth() + 1)
document.write(".")
document.write(curdate.getFullYear())
function legalAge()
{
var ageString;
var legalAge=21;
var ageNum;
ageString = prompt ("Please enter your age", " ");
ageNum = parseInt(ageString);
document.write(ageString + "<br>");
if (ageNum >= legalAge)
{alert ("Let's Party!");}
else if (ageNum < legalAge)
{alert ("Sorry! You're too young to drink!");}
else if (ageNum < 0)
{alert ("Please enter a valid age"); }
else
{alert ("Please enter a valid age"); }
}
</SCRIPT>
</BODY>
</HTML>
I've been working on this and it's almost what I want.
I want to obtain the user's current age by comparing their date of birth
(user inputs) to the current date.
I know how to get the Current Date but I'm not finding how to calculate the
Current Date minus the User's Birthday.
It would be something like yourage = curdate - bday;
I will then use the results to determine if the User is Over 21 or Under 21.
Any help would be greatly appreciated!
I'm going nuts trying to figure this out.
Is there an Easier Book to learn this stuff other than the "Begining
JavaScript 2nd Edition".
Thanks again for any help. I'm a total novice.
=======================
<HTML>
<HEAD>
<TITLE>Legal Drinking Age </TITLE>
<form>
<input type="button" value="Submit" onClick="legalAge()">
</form>
</HEAD>
<BODY>
<script language="JavaScript" type="text/JavaScript">
var curdate = new Date()
document.write(curdate.getDate())
document.write(".")
document.write(curdate.getMonth() + 1)
document.write(".")
document.write(curdate.getFullYear())
function legalAge()
{
var ageString;
var legalAge=21;
var ageNum;
ageString = prompt ("Please enter your age", " ");
ageNum = parseInt(ageString);
document.write(ageString + "<br>");
if (ageNum >= legalAge)
{alert ("Let's Party!");}
else if (ageNum < legalAge)
{alert ("Sorry! You're too young to drink!");}
else if (ageNum < 0)
{alert ("Please enter a valid age"); }
else
{alert ("Please enter a valid age"); }
}
</SCRIPT>
</BODY>
</HTML>