I've done a basic form validation but there's more to the form validation that I need --- this would be if the entry made in the field isn't correct, then it will disable the remainder of the form and prevent the user from making any other entries.
The reason for disabling the remainder of the form, I do not want the user to submit the form with a blank field, or a field with an incorrect entry (which isn't setup in the validator code). Right now the validator code I created, only validates BUT the user can complete the remainder of the form regardless if the entry is correct or not.
Here's the validator code I have ... If anyone can help me out, much appreciated and THANKS!
<html>
<head>
<script language="JavaScript1.2">
<!-- this validates the piw code
var validated=false
function validatePIW(form) {
var str = form.PIW_CODE.value;
var re = /^10246$|^1183$|^11$|^165$|^1609$|^42$|^10133$/i;
if (form.PIW_CODE.value == ""
{
alert("Please enter a PIW Code"
;
form.PIW_CODE.focus();
return false;
}
if (re.test(str)) {
form.PIW_CODE.value = str.toUpperCase();
if(validated)
{
return true
}
else if(!validated){
alert("This is a valid PIW Code. Continue with remainder of form."
; //remove this line when you use
the code
}
validated=true
return false
}
alert("" + str + " is an invalid PIW code! Click on the PIW Code Help link to find out more about
PIW Codes."
;
form.PIW_CODE.select();
form.PIW_CODE.focus();
return false;
}
// -->
</script>
</head>
<body>
<FORM METHOD=post ACTION="bin/request.pl" onSubmit="return validatePIW(this)">
<table border=0">
<tr valign="top">
<td><b>PIW Code:</b></td>
<td><input name="PIW_CODE" size="10" maxlength="10" type="number"> <input type="button"
onclick='validatePIW(this.form)' value="Validate PIW" name="validate"></td>
</tr>
<tr valign="top">
<td>Name</td>
<td><input name="Name" size=10></td>
</tr>
<tr valign="top">
<td>Address</td>
<td><input name="Address" size=10></td>
</tr>
<tr valign="top">
<td>Userid</td>
<td><input name="userid" size=10></td>
</tr>
<tr valign="top">
<td></td>
<td><input type="submit" value="Submit" name="Submit"></td>
</tr>
</table>
</form>
</body>
</html>
The reason for disabling the remainder of the form, I do not want the user to submit the form with a blank field, or a field with an incorrect entry (which isn't setup in the validator code). Right now the validator code I created, only validates BUT the user can complete the remainder of the form regardless if the entry is correct or not.
Here's the validator code I have ... If anyone can help me out, much appreciated and THANKS!
<html>
<head>
<script language="JavaScript1.2">
<!-- this validates the piw code
var validated=false
function validatePIW(form) {
var str = form.PIW_CODE.value;
var re = /^10246$|^1183$|^11$|^165$|^1609$|^42$|^10133$/i;
if (form.PIW_CODE.value == ""
alert("Please enter a PIW Code"
form.PIW_CODE.focus();
return false;
}
if (re.test(str)) {
form.PIW_CODE.value = str.toUpperCase();
if(validated)
{
return true
}
else if(!validated){
alert("This is a valid PIW Code. Continue with remainder of form."
the code
}
validated=true
return false
}
alert("" + str + " is an invalid PIW code! Click on the PIW Code Help link to find out more about
PIW Codes."
form.PIW_CODE.select();
form.PIW_CODE.focus();
return false;
}
// -->
</script>
</head>
<body>
<FORM METHOD=post ACTION="bin/request.pl" onSubmit="return validatePIW(this)">
<table border=0">
<tr valign="top">
<td><b>PIW Code:</b></td>
<td><input name="PIW_CODE" size="10" maxlength="10" type="number"> <input type="button"
onclick='validatePIW(this.form)' value="Validate PIW" name="validate"></td>
</tr>
<tr valign="top">
<td>Name</td>
<td><input name="Name" size=10></td>
</tr>
<tr valign="top">
<td>Address</td>
<td><input name="Address" size=10></td>
</tr>
<tr valign="top">
<td>Userid</td>
<td><input name="userid" size=10></td>
</tr>
<tr valign="top">
<td></td>
<td><input type="submit" value="Submit" name="Submit"></td>
</tr>
</table>
</form>
</body>
</html>