Well the way you were going about it was a good way, but in my opinion not the esiest. I like to go the easy way out hehehehe
So i played with the function and heres what i came up with, it seemed to work for me
I've boldfaced what i changed
<HTML>
<HEAD>
<TITLE>Assignment 3, Exercise 1</TITLE>
<script LANGUAGE="JavaScript">
function clearField(field) {
// Check if field contains the default value
if (field.value == field.defaultValue) {
// It does, so clear the field
field.value = "";
}
}
function checkField(field) {
// Check if user has entered information in the field
if (field.value == "") {
// User has not entered anything
field.value = field.defaultValue;
}
}
function checkAge(field) {
var age = document.forms[0].age.value;
if (age >= 17 && age <=21) {
alert("Your Of Age")
//Do whatever if the age is correct.
}else{
alert("Your Not Of Age")
document.forms[0].age.value="Your Age"
}
}
</script>
</HEAD>
<BODY>
<H1>Beverley Curia</H1>
<H2>Assignment 3, Week 4, Exercise 1 (341.htm)</H2>
<P>Questions?
<BR>Send me an email: <A HREF="http://bevcuria@hotmail.com">bevcuria@hotmail.com</A></P>
<BR>
<BR>
<BR>
Extend the functionality of 341.htm to check whether the age entered is in a specific numeric range - (ie, at least 18 & less 21) - and, if not, warn the user and return the default value.
<BR>
<BR>
<table border="0" width="95%" cellspacing="0" cellpadding="0">
<tr>
<td width="100%" align="center"><form METHOD="POST">
<div align="center"><center><table border="2" cellpadding="5" bgcolor="#FAFAC8">
<tr>
<td align="center"><input TYPE="text" NAME="name" VALUE="Name" onFocus="clearField(this);" onBlur="checkField(this);" size="20"></td>
</tr>
<tr>
<td align="center"><input TYPE="text" NAME="email" VALUE="E-mail Address" onFocus="clearField(this);" onBlur="checkField(this);" size="20"></td>
</tr>
<tr>
<td align="center"><input TYPE="text" NAME="age" VALUE="Your Age" onFocus="clearField(this);" onBlur="checkAge(this);" size="20"></td>
</tr>
</table>
</center></div>
</form>
</td>
</tr>
</table>
</center></div>
<HR>
<P><CENTER><A HREF="http://www.geocities.com/bevcuria/assign2.html">Return to my Assignment 2 List</A></CENTER></P>
</BODY>
</HTML>
Hope this works for ya
