S
Sue
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>JavaScript Project</title>
<SCRIPT LANGUAGE="JAVASCRIPT">
<!--Hide from old browsers
function Validate(DataEntry) {
// validate the Firstname
var FstName=document.Register.FirstName.value
if (FstName == " ") {
alert("Please enter your Firstname")
document.Register.FirstName.value=" "
document.Register.FirstName.focus()
}
else {
// validate the Lastname
var LstName=document.Register.LastName.value
if (LstName == " ") {
alert("Please enter your Lastname")
document.Register.LastName.value=" "
document.Register.LastName.focus()
}
else {
// validate Age as be numeric
var YearsOld=document.Register.Age.value
var YearsOld=parseInt(YearsOld,10)
if (isNaN(YearsOld)) {
alert("Age is not numeric")
document.Register.Age.value=" "
document.Register.Age.focus();
}
else {
// validate the @ sign and the period as being the fourth
from the last character in an e-mail address
var RegeMail=document.Register.eMail.value
var atSign = RegeMail.indexOf("@")
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.Register.eMail.value = " "
document.Register.eMail.focus()
}
else {
// validate the Gender in a drop down menu
var sex=document.forms[0].Gender.selectedIndex;
if (sex==0) {
alert("You must select your GENDER from the drop-down
Menu.");
document.forms[0].Gender.focus();
}
else
{
Gender_selection=document.forms[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> Enter 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">Male
<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="Validate(Register)">
<Input
Type="Reset">      </td>
</tr>
<!-- ending of the second line of the form for entering data. -->
</table>
</form>
</body>
</html>
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>JavaScript Project</title>
<SCRIPT LANGUAGE="JAVASCRIPT">
<!--Hide from old browsers
function Validate(DataEntry) {
// validate the Firstname
var FstName=document.Register.FirstName.value
if (FstName == " ") {
alert("Please enter your Firstname")
document.Register.FirstName.value=" "
document.Register.FirstName.focus()
}
else {
// validate the Lastname
var LstName=document.Register.LastName.value
if (LstName == " ") {
alert("Please enter your Lastname")
document.Register.LastName.value=" "
document.Register.LastName.focus()
}
else {
// validate Age as be numeric
var YearsOld=document.Register.Age.value
var YearsOld=parseInt(YearsOld,10)
if (isNaN(YearsOld)) {
alert("Age is not numeric")
document.Register.Age.value=" "
document.Register.Age.focus();
}
else {
// validate the @ sign and the period as being the fourth
from the last character in an e-mail address
var RegeMail=document.Register.eMail.value
var atSign = RegeMail.indexOf("@")
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.Register.eMail.value = " "
document.Register.eMail.focus()
}
else {
// validate the Gender in a drop down menu
var sex=document.forms[0].Gender.selectedIndex;
if (sex==0) {
alert("You must select your GENDER from the drop-down
Menu.");
document.forms[0].Gender.focus();
}
else
{
Gender_selection=document.forms[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> Enter 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">Male
<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="Validate(Register)">
<Input
Type="Reset">      </td>
</tr>
<!-- ending of the second line of the form for entering data. -->
</table>
</form>
</body>
</html>