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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form not checking for required info

Status
Not open for further replies.

SlowFlight

Programmer
Jan 2, 2003
33
US
I have a form set up at:
It has some script to check for required information. But for some reason the function does not return the expected error message when required information is not entered.

Could someone please look it over and see if you can see what I am doing wrong? I have gone over it several times and just can't see what I am missing.

Skip Meisch

SV "Slow Flight"
1977 Catalina 22 Swing Keel
 
SlowFlight,

[1] Common mistake on the submit button here.
[tt]
<form action=" method="post" name="eventEntryForm" id="eventEntryForm" [red]onsubmit="return checkMandatory();"[/red]>
[/tt]
Then change the submit button to type button. Also do not use submit as name. Then, add onclick handling to the function.
[tt]
<input type="[blue]button[/blue]" name="submit[blue]xx[/blue]" id="submit[blue]xx[/blue]" value="Submit" [blue]onclick="return checkMandatory();"[/blue] />
[/tt]
Then in the function, spare some return etc and at the end, you add the submit functionality.
[tt]
if (error_string != "") {
return false;
} else {
document.eventEntryForm.submit();
return true; //optional
}
[/tt]
[2] There are typos on "email".
[tt]
var the_email = window.document.eventEntryForm.[red]Email[/red].value;
[/tt]and[tt]
if (window.document.eventEntryForm.[red]Email[/red].value == "")[/tt]

These are the major changes you need to make and it then would perform. The rest can be improved afterward.

regards - tsuji
 
There's nothing wrong with the way you're calling the function. The onsubmit is often the preferred method of calling a validation function.

Make your last lines of code like this (remove the else):

Code:
    if (window.document.eventEntryForm.activities.value == "")
        error_string += "What activities would you like?\n";

    error_string = "We found the following ommisions in your form: \n\n" + error_string;
    alert(error_string);
    return false;

*cLFlaVA
----------------------------
[tt]tastes great, less filling.[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
cLFlaVA,

Removing the "else" did not help. Could there be a problem with my use of braces? I noticed you did not duplicate my braces in your copy of my code.

SV "Slow Flight"
1977 Catalina 22 Swing Keel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top