Hi,
I am working on validating a form using regular expressions. The only method I know is by validating the form line by line.
example:
[code=php]function ValidForm2(passForm){
if (!myfirst.test(passForm.bfname.value)) {
alert (“Please enter a valid firstname”);
passForm.bfname.focus()
passForm.bfname.select()
return false;
}
if (passForm.bfname.value == “”) {
alert (“Please enter all mandatory fields”);
passForm.bfname.focus()
passForm.bfname.select()
return false;
}
…….ETC
……..
return true;
}
I have 2 questions:
1) How can we in javascript display the alert in the form itself and not as a popup. When the user clicks submit if any of the fields values if not valid, one error message appears on the top and perhaps some text next to the field(s)
2) Using my method of alerts for each field (as in the code above), I get the alertbox and when I click on it I get transferred to the next page where my form is POSTING to. And obviously there I get an SQL message because my query wouldn’t run because the data entered in the formwas not valid.
Why is this happening (why does the form page immediately takes me to the next page immediately when i click ok on the alert box, without focusing on the field that had the error according to my function)?