...

View Full Version : Form Validation-Submitting When Fields Not Complete



sdg
07-25-2002, 02:37 PM
Hello,

I have some Javascript that checks to see if the user has entered all the required fields. If the fields are left blank, then a message appears telling them that they didn't complete the particular field.

This part of the code works just fine, but after the user clicks the "OK" button to close the message, the code proceeds to submit the form regardless.

Here is the Javascript:

function verify() {
var themessage = "You are required to complete the following fields: ";

if ((document.formx.Chapter[0].checked == false) && (document.formx.Chapter[1].checked == false)) {
themessage = themessage + " - Chapter";
}

if (themessage == "You are required to complete the following fields: ") {
return(true);
}
else {
alert(themessage);
return(false);
}
}
// End -->

</script>


Here is the portion of the HTML that calls the submit:

<form name="formx" method="post" action="submit.asp" onSubmit="verify();">

Here is the portion of the HTML of the form where the "Chapter" option is selected:

<INPUT type="radio" name="Chapter" value="Philadelphia" size="20"></FONT><FONT face="Garamond">Philadelphia</FONT><FONT size="2" face="Arial"><BR>
<INPUT type="radio" name="Chapter" value="Triple Cities"></FONT><FONT face="Garamond">Triple
Cities</FONT></p>


I can also provide the URL to test it out yourself.

Much thanks in advance.

-Scott

Zvona
07-25-2002, 03:17 PM
I made a fully functional yet compact example once. It can be found from : http://www24.brinkster.com/zvona/zValidate.html .
The fields and dialogs are in Finnish, but I think you get the idea anyway.

tamienne
07-25-2002, 03:31 PM
add return to your onSubmit

onSubmit="return verify();">



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum