PDA

View Full Version : Problem with field validation any one see my mistake with the if statment?



musher
Mar 26th, 2007, 09:33 PM
I'm trying to learn js and having a problem with a validation routine I'm writing. The if statment below is not working, script is going to registration.php when the passwords do not match.


if (document.registration.password.value!=document.registration.passwordConf.value) {

<html>
<head>
<title>Page 1</title>

</head>

<body>

<script>
<!--
function validateform() {
if(document.registration.firstName.value=="") {
window.alert ("Please Your First Name!");
registration.firstName.focus();
return (false);
}
if(document.registration.lastName.value=="") {
window.alert ("Please Enter your Last Name!");
registration.lastName.focus();
return (false);
}
if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(registration.email.value))) {
alert ("Missing or Invalid E-mail Address! Please re-enter.");
registration.email.focus();
return (false);
}
if(document.registration.companyName.value=="") {
window.alert ("Please Enter your Company Name!");
registration.companyName.focus();
return (false);
}
if (!(/^[1-9]\d{2}-\d{3}-\d{4}$/.test(registration.phone.value))) {
alert ("Invalid Phone Number! Please re-enter 123-456-7890.");
registration.phone.focus();
return (false);
}
if ((document.registration.password.value=="") || (document.registration.passwordConf.value=="")) {
alert ("Password and Confirm Password can not be blank!");
registration.password.focus();
return (false);
}
if (document.registration.password.value!=document.registration.passwordConf.value) {
alert ("Please make sure your passwords match!");
registration.password.focus();
return (false);
}
}
//-->
</script>

<form method="POST" name="registration" action="scripts/registration.php" onSubmit="return validateform( this )">
<table width="360" border="0" cellspacing="0" cellpadding="2">
<tr>
<td colspan="2" class="msgblock"><?php echo $var_message; ?></td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td class="colmhdr">First Name: </td>
<td align="left"><input name="firstName" type="text" class="textbox" maxlength="255" /></td>
</tr>
<tr>
<td class="colmhdr">Last Name: </td>
<td align="left"><input name="lastName" type="text" class="textbox" maxlength="255" /></td>
</tr>
<tr>
<td class="colmhdr">Email Address: </td>
<td align="left"><input name="email" type="text" class="textbox" maxlength="50" /></td>
</tr>
<tr>
<td class="colmhdr">Company Name: </td>
<td align="left"><input name="companyName" type="text" class="textbox" maxlength="255" /></td>
</tr>
<tr>
<td class="colmhdr">Phone: </td>
<td align="left"><input name="phone" type="text" class="textbox" maxlength="20" /></td>
</tr>
<tr>
<td class="colmhdr">Password: </td>
<td align="left"><input name="password" type="text" class="textbox" maxlength="100" /></td>
</tr>
<tr>
<td class="colmhdr">Verify Password: </td>
<td align="left"><input name="password2" type="text" class="textbox" maxlength="100" /></td>
</tr>
<tr><td colspan="2">&nbsp;</td></tr>
<tr>
<td class="tdRichText" colspan="3"><input name="submit" type="submit" id="submit" class="submit" value="Submit"></td>
</tr>
</table>
</form>
</body>
</html>

Arty Effem
Mar 26th, 2007, 10:13 PM
I'm trying to learn js Fine - the first thing to learn is use of the Javascript console, which will describe the error.
The Firefox/Mozilla console is the best.

musher
Mar 26th, 2007, 11:41 PM
Fine - the first thing to learn is use of the Javascript console, which will describe the error.
The Firefox/Mozilla console is the best.

Thanks Arty took a bit to fingure out how to use FF Console, but I figured out the problem.