S
Sue
In this code why is it that when I press the SUBMIT button the focus
only goes back to the Numeric field. What do I need to do to correct
this problem?
Sue
<html>
<head>
<title>JavaScript Project</title>
<SCRIPT LANGUAGE="JAVASCRIPT">
<!--Hide from old browsers
function Validate() {
var themessage = "You are required to complete the following fields:
";
// validate the Firstname
if (document.Register.FirstName.value=="") {
alert("Please enter your Firstname");
document.Register.FirstName.value="";
document.Register.FirstName.focus();
}
else {
// validate the Lastname
if (document.Register.LastName.value=="") {
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
{
//alert if fields are empty and cancel form submit
if (themessage == "You are required to complete the following fields:
") {
document.Register.submit();
}
else {
alert(themessage);
return false;
}
}
}
}
}
}
}
//-->
</script>
</head>
<body>
<center>
<form name=Register method="post" action="">
<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. -->
<tr>
<td></td>
</tr>
<!-- 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="Submit Request"
onclick="Validate();">
<Input Type="Reset"></td>
</tr>
<!-- ending of the second line of the form for entering data. -->
</body>
</html>
only goes back to the Numeric field. What do I need to do to correct
this problem?
Sue
<html>
<head>
<title>JavaScript Project</title>
<SCRIPT LANGUAGE="JAVASCRIPT">
<!--Hide from old browsers
function Validate() {
var themessage = "You are required to complete the following fields:
";
// validate the Firstname
if (document.Register.FirstName.value=="") {
alert("Please enter your Firstname");
document.Register.FirstName.value="";
document.Register.FirstName.focus();
}
else {
// validate the Lastname
if (document.Register.LastName.value=="") {
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
{
//alert if fields are empty and cancel form submit
if (themessage == "You are required to complete the following fields:
") {
document.Register.submit();
}
else {
alert(themessage);
return false;
}
}
}
}
}
}
}
//-->
</script>
</head>
<body>
<center>
<form name=Register method="post" action="">
<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. -->
<tr>
<td></td>
</tr>
<!-- 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="Submit Request"
onclick="Validate();">
<Input Type="Reset"></td>
</tr>
<!-- ending of the second line of the form for entering data. -->
</body>
</html>