Networking | Hardware | Software | Multimedia | System | Unix&Linux | MBA

Home>>Hardware>>Am I missing something, Validating?

Am I missing something, Validating?

sylvielaps
03-16-2006, 12:19 AM
I can't seem to figure out if I'm missing something, or just plain new at this?! My code below is just to validate the form prior to submission, can anyone see anything on the top of their heads that is missing, or am I on the wrong track maybe? Thanks in advance!

<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>

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>

sylvielaps
03-16-2006, 01:19 AM
See, I knew it was somethign stuipd like that! Many Thanks for spotting that. This is just for an assignment to ensure something is put into the fields, I realize that for the telephone number I can check if it's numeric etc...

But I thank you for that, it was killing me!!!:thumbsup:

greasonwolfe
03-16-2006, 01:26 AM
No problem. Sometimes it is the simple things that kill us.


 

TOP

Hyperthreading hurts s
HP sharpens blade PC l
Apple goes for Quad po
Itanium gets scaled do

For more info

HP sharpens blade PC l
Hyperthreading hurts s
can not call click() i
script does not work o
smart menu 
write to an html file 
FireFox doesn't recogn
Changing e.keyCode (e.
Clearing a range creat
UPDATE: My mouse over 

News Archive

onChange Help 
beforeload? vs onload.
Problem with document.
decreasing my javascri
Problem with \\ and \ 
how to stop scrolling?
Change Label Text Colo
Can I forward a page b
2 javascript functions
Validating a textbox 

Related stories:

Mozilla + Mediplayer + Javascript
Looking for a script that scrolls
Problem in Script
Stock Data
Restrict Scrolling
Make the only clickable area the center of the screen
validate string
Having trouble with some javascript code...
Script for date validation...

Copyright@2004-2005 www.zzcoke.com All Right Reserved

advanced web statistics