Hello! I am back with another question.
Remember I am a new JavaScript student and I am aware that this code
does not check for all the possibilities and that as a "NEW"
JavaScript student I am not expected to check for everything.
At any rate, the problem I am having with the following code is that
it does not clear the fields once I press the SEND button. So can
anyone here enlighten me as to what is causing the problem.
*************** *************** *************** *************** **************
<html>
<head>
<title>JavaScri pt Project</title>
<SCRIPT LANGUAGE="JAVAS CRIPT">
<!--Hide from old browsers
function Validate(DataEn try) {
// validate the Firstname
var FstName=documen t.Register.Firs tName.value
if (FstName == " ") {
alert("Please enter your Firstname")
document.Regist er.FirstName.va lue=" "
document.Regist er.FirstName.fo cus()
}
else {
// validate the Lastname
var LstName=documen t.Register.Last Name.value
if (LstName == " ") {
alert("Please enter your Lastname")
document.Regist er.LastName.val ue=" "
document.Regist er.LastName.foc us()
}
else {
// validate Age as be numeric
var YearsOld=docume nt.Register.Age .value
var YearsOld=parseI nt(YearsOld,10)
if (isNaN(YearsOld )) {
alert("Age is not numeric")
document.Regist er.Age.value=" "
document.Regist er.Age.focus();
}
else {
// validate the @ sign and the period as being the fourth
from the last character in an e-mail address
var RegeMail=docume nt.Register.eMa il.value
var atSign = RegeMail.indexO f("@")
var Period=document .Register.eMail .value
var PPeriod = Period.indexOf( '.');
var LPeriod = Period.length - 4
if (RegeMail == " " || atSign == -1 || LPeriod !=
PPeriod) {
alert("Please enter a valid e-mail address")
document.Regist er.eMail.value = " "
document.Regist er.eMail.focus( )
}
else {
// validate the Gender in a drop down menu
var sex=document.fo rms[0].Gender.selecte dIndex;
if (sex==0) {
alert("You must select your GENDER from the drop-down
Menu.");
document.forms[0].Gender.focus() ;
}
else
{
Gender_selectio n=document.form s[0].Gender.options[sex].value;
return true;
}
}
}
}
}
}
//-->
</script>
</head>
<body>
<FORM Name="Register" >
<table border="0" width="90%">
<!-- Begining of the first line of the form for entering data. -->
<tr>
<td>Enter Your Firstname :</td><td align="center">
<Input Type="text" Name="FirstName " value=" "></td>
<td> Ente r Your Age :</td> <td align="center">
<Input Type="numeric" Name="Age" value=" "></td>
<td align="center"> Select your : <SELECT NAME="Gender" SIZE=1 >
<OPTION SELECTED VALUE=""> --- Select Gender ---
<OPTION VALUE="Male">Ma le
<OPTION VALUE="Female"> Female
</SELECT>
</td>
</tr>
<!-- ending of the first line of the form for entering data. -->
<!-- Begining of the second line of the form for entering data. -->
<tr>
<td align="center"> Enter Your Lastname :</td><td align="center">
<Input Type="text" Name="LastName" value=" "></td>
<td align="center"> Enter Your Email Address :</td> <td
align="center">
<Input Type="text" Name="eMail" value=" "></td>
<td align="right">< Input Type="button" Value="Send"
onClick="Valida te(Register)">
<Input
Type="Reset">&n bsp  &n bsp  </td>
</tr>
<!-- ending of the second line of the form for entering data. -->
</table>
</form>
</body>
</html>
Comment