Hello,
I am trying to get this simple validation script to work but can't. Does anyone see the reason why?
I really appreciate and would like to thank anyone who takes the time to look at this.
<html>
<head>
<script type="text/javascript">
function validate()
{
x=document.myForm
seats=x.txtNumberOfSeats.value
firstname=x.txtFirstName.value
lastname=x.txtLastName.value
phonenumber=x.txtPhoneNumber.value
submitOK="True"
if (seats<1 ||(seats>20)
{
alert("The number of seats must be between 1 and 20")
submitOK="False"
}
if (firstname.length=0)
{
alert("Your must enter your first name.")
submitOK="False"
}
if (lastname.length=0)
{
alert("Your must enter your last name.")
submitOK="False"
}
if (phonenumber.length=0)
{
alert("Your must enter your phone number.")
submitOK="False"
}
if (submitOK=="False")
{
return false
}
}
</script>
</head>
<body>
<form name="myForm" action="javascripttest.html" method="get" onsubmit="return validate()">
<table>
<tr>
<td>First Name:</td>
<td><input type="text" name="txtFirstName" size="20"></td>
</tr>
<tr>
<td>Last Name:</td>
<td><input type="text" name="txtLastName" size="20"></td>
</tr>
<tr>
<td>Phone Number:</td>
<td><input type="text" name="txtPhoneNumber" size="20"></td>
</tr>
<tr>
<td>Date:</td>
<td><input type="text" name="txtDate" size="20"></td>
</tr>
<tr>
<td>Flight Number:</td>
<td>
<select name="lstFlights">
<option value="101">101
<option value="201">201
<option value="301">301
</select>
</td>
</tr>
<tr>
<td>Number of Seats:</td>
<td><input type="text" name="txtNumberOfSeats" size="20"></td>
</tr>
<tr>
<td>
Smoking:<input type="radio" name="optSmokingPref" value="smoking">
</td>
<td>
Non-Smoking:<input type="radio" checked name="optSmokingPref" value="non-smoking">
</td>
</tr>
<tr>
<td><input type="submit" value="Submit"></td>
<td>Thank You</td>
</tr>
</table>
</form>
</body>
</html>
I am trying to get this simple validation script to work but can't. Does anyone see the reason why?
I really appreciate and would like to thank anyone who takes the time to look at this.
<html>
<head>
<script type="text/javascript">
function validate()
{
x=document.myForm
seats=x.txtNumberOfSeats.value
firstname=x.txtFirstName.value
lastname=x.txtLastName.value
phonenumber=x.txtPhoneNumber.value
submitOK="True"
if (seats<1 ||(seats>20)
{
alert("The number of seats must be between 1 and 20")
submitOK="False"
}
if (firstname.length=0)
{
alert("Your must enter your first name.")
submitOK="False"
}
if (lastname.length=0)
{
alert("Your must enter your last name.")
submitOK="False"
}
if (phonenumber.length=0)
{
alert("Your must enter your phone number.")
submitOK="False"
}
if (submitOK=="False")
{
return false
}
}
</script>
</head>
<body>
<form name="myForm" action="javascripttest.html" method="get" onsubmit="return validate()">
<table>
<tr>
<td>First Name:</td>
<td><input type="text" name="txtFirstName" size="20"></td>
</tr>
<tr>
<td>Last Name:</td>
<td><input type="text" name="txtLastName" size="20"></td>
</tr>
<tr>
<td>Phone Number:</td>
<td><input type="text" name="txtPhoneNumber" size="20"></td>
</tr>
<tr>
<td>Date:</td>
<td><input type="text" name="txtDate" size="20"></td>
</tr>
<tr>
<td>Flight Number:</td>
<td>
<select name="lstFlights">
<option value="101">101
<option value="201">201
<option value="301">301
</select>
</td>
</tr>
<tr>
<td>Number of Seats:</td>
<td><input type="text" name="txtNumberOfSeats" size="20"></td>
</tr>
<tr>
<td>
Smoking:<input type="radio" name="optSmokingPref" value="smoking">
</td>
<td>
Non-Smoking:<input type="radio" checked name="optSmokingPref" value="non-smoking">
</td>
</tr>
<tr>
<td><input type="submit" value="Submit"></td>
<td>Thank You</td>
</tr>
</table>
</form>
</body>
</html>