1

I have a function that triggers a number of other functions:

function formvalidation()
{
    ZeroSite();
    BlankPC();
    BlankSite();
    BlankSeats();
}// End of formvalidation

and a form like so:

<form id="quote" name="quote" method="get" onSubmit='return formvalidation();' action="testing.php">

The problem being, if one of the individule functions returns flase then the form still gets submitted, is there any way of passing the return false to the parent function?

Thanks for looking, B.

1
  • 1
    Well your formvalidation function doesn't return anything - that's the first thing you need to fix Commented Jun 10, 2011 at 10:22

4 Answers 4

2

Check if all the functions return true, if not return false. Example below

function formvalidation() {
    return (ZeroSite() && BlankPC() && BlankSite() && BlankSeats());
}
Sign up to request clarification or add additional context in comments.

1 Comment

And you're certain the functions do return false - do you get any javascript errors, errors might prevent the function from being run correctly and not returning false to the onsubmit. Possibly try putting a portion of the JS and HTML on jsfiddle.net
1

I see 3 people have already been kind enough to give you identical and perfectly good answers :-) However, using bitwise ANDs instead, you can make sure all the functions are called, even though a previous one has returned false.

function formvalidation() {
    return Boolean( ZeroSite() & BlankPC() & BlankSite() & BlankSeats() );
}

Comments

0

Try something like:

function formvalidation() {
    return(ZeroSite() && BlankPC() && BlankSite() && BlankSeats());
}

If any of your other functions return false, the return statement will evaluate to false and the main function will also return false.

Comments

0

When all of these functions just return a value you must check for that value...

function formvalidation()
{
    return (ZeroSite() && BlankPC() && BlankSite() && BlankSeats());
}// End of formvalidation

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.