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

Jul 25th, 2002, 01:37 PM

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: ") {
else {
// End -->


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

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

Much thanks in advance.


Jul 25th, 2002, 02: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.

Jul 25th, 2002, 02:31 PM
add return to your onSubmit

onSubmit="return verify();">