validation question...

wxdqz

New Member
I'm trying to validate a form with several text fields. Essentially what I did was create functions for each text field, and then create a master function that checks if each function validates, if not it should return false. With what I have right now, if the first text field is correct but the second one is incorrect, the form will submit anyway. Below is an example of the code that I am using:

<script>

function chkOne() {
if (document.form.field1.length == 0) {
alert("Please enter text")
}
return false
}

function chkTwo() {
if (document.form.field2.length == 0) {
alert("Please enter more text")
}
return false
}


function master(thisform) {

var mstVal = false

mstVal = chkOne(form);
mstVal = chkTwo(form);

return mstVal;

</script>

<form name="form" method="post" action="page.htm" onSubmit="return master(form)">

<input type="text" name="field1"> <br>
<input type="text" name="field2"> <br>
<input type="button" name="button" value=http://www.webdeveloper.com/forum/archive/index.php/"submit">


</form>



------------------


This is the best way I could think of doing this. Of course, I have more text fields that above, and I cut out some tags to make it quicker to read. Any suggestions will be greatly appreciated!

Thanks,

Brian
 
Back
Top