www.webdeveloper.com
Results 1 to 2 of 2

Thread: Need help with an onsubmit return script that will check 2 functions

  1. #1
    Join Date
    Jan 2013
    Posts
    1

    Need help with an onsubmit return script that will check 2 functions

    I am trying to prevent submission of a form if either or both of 2 functions return false. I've tried calling the functions in my form this way:

    <form action="tuition-calculator.php" name="orderform" id="tuition-schedule" method="post" onsubmit="return (tuesThurs() && setTuition())">, but it doesn't stop the submission, even if the results are false.

    So...now I've tried this:
    (in header)

    <script type="text/javascript">
    function formValidation(myForm)
    {
    var result = tuesThurs(myForm);
    var result2 = setTuition(myForm);
    results = result && result2;
    return results;
    }
    </script>

    (in body)

    <form action="tuition-calculator.php" name="orderform" method="post" onsubmit="return formValidation(this)">

    If the values are "false" for both functions, the proper alerts appear and the submission doesn't happen. If I change my entries so that tuesThurs returns a "true" but setTuition returns a false, the alert for setTuition appears, but the submission goes through anyway. I do not want it to be submitted until both functions are true.

    Any suggestions?

  2. #2
    Join Date
    Aug 2008
    Location
    Sweden
    Posts
    227
    Are you sure you're returning the correct values from both tuesThurs and setTuition? And there are no errors? Because both of the above methods are correct and should work.
    New to web development or in need of a good reference? Check out the Mozilla Developer Network or W3Schools.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles