greasonwolfe
03-16-2006, 01:06 AM
I am guessing you are getting a syntax error at line 13? You missed an opening parenthesis in that line. The way you had it written checked only the first argument. Adding that will clear the error. Of course, it is still possible that your validation techniques wont fully suffice. With what you have, someone can enter any set of characters they want for the phone number including just a single character. You might want to look into regular expressions to determine if the entries are in line with what is required, assuming that this is the actual code you are using and not a brief mock up.
<html>
<head>
<title>Registration</title>
<script language="Javascript">
function ValidateRegistration()
{
if ((document.Registration.fname.value == "")|| (document.Registration.lname.value == "") || (document.Registration.address.value == "")
|| (document.Registration.telephone.value ==""))
{
window.alert("Please enter your first, last name, address and phone number");
return false;
}
else if ((document.Registration.email.value == "") || (document.Registration.email.indexOf("@", 0) < 0) || (document.Registration.email.indexOf(".", 0) < 0))
{
window.alert("Please enter a valid e-mail address");
return false;
}
else if (!document.Registration.card[0].checked && !document.Registration.card[1].checked && !document.Registration.card[2].checked && !document.Registration.card[3].checked)
{
window.alert("Please choose a credit card");
return false;
}
else if (document.Registration.age.selectedIndex < 1)
{
alert("Please select your age range!");
return false;
}
return true;
}
</script>
</head>
<body>
<font size="4" face="ARIAL, HELVETICA" color="blue">
<b>Please enter the following data</b></font><br/>
<form name="Registration" action="processRegistration.asp" method="POST" onSubmit="return ValidateRegistration();">
<p><font size="4" face="arial, helvetica">
<table>
<tr>
<td>First name:</td>
<td><input type="text" name="fname" size="20"></td>
</tr>
<tr>
<td>Last name:</td>
<td><input type="text" name="lname" size="20"></td>
</tr>
<tr>
<td>Address:</td>
<td><input type="text" name="address" size="20"></td>
</tr>
<tr>
<td>Telephone Number:</td>
<td><input type="text" name="telephone" size="20"></td>
</tr>
<tr>
<td>Email:</td>
<td><input type="text" name="email" size="20"></td>
</tr>
<tr>
<td>Please input your Credit Card Type: </td>
<tr>
<td><input type="radio" name="card" id="r1" value="mastercard"> MasterCard</td></tr>
<tr><td><input type="radio" name="card" id="r2" value="visa"> VISA</td></tr>
<tr><td><input type="radio" name="card" id="r3" value="amex"> American Express</td></tr>
<tr><td><input type="radio" name="card" id="r4" value="other"> Other</td></tr>
<tr>
<td>Choose your age range:</td></tr>
<td>
<select name="age">
<option value="10-20">10-20
</option>
<option value="21-30">21-30
</option>
<option value="31-40">31-40
</option>
<option value="41-50">41-50
</td>
</option>
</select><br/>
<table>
<tr><td><input type="submit" value="OK" name="submit">
<input type="Reset" value="Cancel" name="reset"></td></tr>
</font>
</p><font size="4" face="arial, helvetica"></font>
</form>
</body>
</html>
<html>
<head>
<title>Registration</title>
<script language="Javascript">
function ValidateRegistration()
{
if ((document.Registration.fname.value == "")|| (document.Registration.lname.value == "") || (document.Registration.address.value == "")
|| (document.Registration.telephone.value ==""))
{
window.alert("Please enter your first, last name, address and phone number");
return false;
}
else if ((document.Registration.email.value == "") || (document.Registration.email.indexOf("@", 0) < 0) || (document.Registration.email.indexOf(".", 0) < 0))
{
window.alert("Please enter a valid e-mail address");
return false;
}
else if (!document.Registration.card[0].checked && !document.Registration.card[1].checked && !document.Registration.card[2].checked && !document.Registration.card[3].checked)
{
window.alert("Please choose a credit card");
return false;
}
else if (document.Registration.age.selectedIndex < 1)
{
alert("Please select your age range!");
return false;
}
return true;
}
</script>
</head>
<body>
<font size="4" face="ARIAL, HELVETICA" color="blue">
<b>Please enter the following data</b></font><br/>
<form name="Registration" action="processRegistration.asp" method="POST" onSubmit="return ValidateRegistration();">
<p><font size="4" face="arial, helvetica">
<table>
<tr>
<td>First name:</td>
<td><input type="text" name="fname" size="20"></td>
</tr>
<tr>
<td>Last name:</td>
<td><input type="text" name="lname" size="20"></td>
</tr>
<tr>
<td>Address:</td>
<td><input type="text" name="address" size="20"></td>
</tr>
<tr>
<td>Telephone Number:</td>
<td><input type="text" name="telephone" size="20"></td>
</tr>
<tr>
<td>Email:</td>
<td><input type="text" name="email" size="20"></td>
</tr>
<tr>
<td>Please input your Credit Card Type: </td>
<tr>
<td><input type="radio" name="card" id="r1" value="mastercard"> MasterCard</td></tr>
<tr><td><input type="radio" name="card" id="r2" value="visa"> VISA</td></tr>
<tr><td><input type="radio" name="card" id="r3" value="amex"> American Express</td></tr>
<tr><td><input type="radio" name="card" id="r4" value="other"> Other</td></tr>
<tr>
<td>Choose your age range:</td></tr>
<td>
<select name="age">
<option value="10-20">10-20
</option>
<option value="21-30">21-30
</option>
<option value="31-40">31-40
</option>
<option value="41-50">41-50
</td>
</option>
</select><br/>
<table>
<tr><td><input type="submit" value="OK" name="submit">
<input type="Reset" value="Cancel" name="reset"></td></tr>
</font>
</p><font size="4" face="arial, helvetica"></font>
</form>
</body>
</html>
