Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form validation that will disable if entry not correct

Status
Not open for further replies.

skw

Instructor
Jun 1, 1999
19
US
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=&quot;JavaScript1.2&quot;>

<!-- 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 == &quot;&quot;) {
alert(&quot;Please enter a PIW Code&quot;);
form.PIW_CODE.focus();
return false;
}
if (re.test(str)) {
form.PIW_CODE.value = str.toUpperCase();
if(validated)
{
return true
}
else if(!validated){
alert(&quot;This is a valid PIW Code. Continue with remainder of form.&quot;); //remove this line when you use
the code
}
validated=true
return false
}
alert(&quot;&quot; + str + &quot; is an invalid PIW code! Click on the PIW Code Help link to find out more about
PIW Codes.&quot;);
form.PIW_CODE.select();
form.PIW_CODE.focus();
return false;
}

// -->
</script>
</head>

<body>
<FORM METHOD=post ACTION=&quot;bin/request.pl&quot; onSubmit=&quot;return validatePIW(this)&quot;>



<table border=0&quot;>

<tr valign=&quot;top&quot;>
<td><b>PIW Code:</b></td>
<td><input name=&quot;PIW_CODE&quot; size=&quot;10&quot; maxlength=&quot;10&quot; type=&quot;number&quot;> <input type=&quot;button&quot;
onclick='validatePIW(this.form)' value=&quot;Validate PIW&quot; name=&quot;validate&quot;></td>
</tr>

<tr valign=&quot;top&quot;>
<td>Name</td>
<td><input name=&quot;Name&quot; size=10></td>
</tr>

<tr valign=&quot;top&quot;>
<td>Address</td>
<td><input name=&quot;Address&quot; size=10></td>
</tr>

<tr valign=&quot;top&quot;>
<td>Userid</td>
<td><input name=&quot;userid&quot; size=10></td>
</tr>

<tr valign=&quot;top&quot;>
<td></td>
<td><input type=&quot;submit&quot; value=&quot;Submit&quot; name=&quot;Submit&quot;></td>
</tr>
</table>
</form>
</body>
</html>



 
How about something simple like when the form initially loads the submit button is hidden. If the validation passes, then the submit button is displayed.

IT might just be an easy way around what you are trying to do. Mise Le Meas,

Mighty :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top