OnSubmitting multiple Functions

Results 1 to 4 of 4

Thread: OnSubmitting multiple Functions

  1. #1
    Nurice Guest

    Default OnSubmitting multiple Functions

    Hi everyone!<BR>I have a form with two functions (And more coming) that all need to return true for the form to pass onto the next page This is the line I&#039m having problems with:<BR><BR>&#060;FORM ACTION="AddUser.asp" NAME="frmUser" METHOD="POST" onSubmit="return IsFormComplete(frmUser); VerifyData();"&#062;<BR><BR>Now, with this syntax, IsFormComplete will go through, and if it&#039s true it skips right past VerifyData. I&#039ve tried "AND" and also "&" but it returns with an error. I&#039ve thought of possibly starting up another function returning one true value if both are true, but I don&#039t know how to go about that- I&#039m a beginner JScripter. Any help is GREATLY appreciated!<BR>-Nurice

  2. #2
    Join Date
    Dec 1969

    Default RE: OnSubmitting multiple Functions

    What you were probably looking for was this:<BR><BR>onSubmit="return IsFormComplete(frmUser) && VerifyData();"&#062;<BR><BR>The && operator in JavaScript (and Java and C and C++) means "return true only if the values on both side of the operator are both true."<BR><BR>It also does a "short circuit": If the first one is false, it stops right there and returns false without calling the second one.<BR><BR>HOWEVER...<BR><BR>For maximum flexibility, I&#039d simply create a "master" validation function which calls both and then returns the results.<BR><BR>Thus:<BR><BR>function validateAll( )<BR>{<BR>&nbsp;&nbsp;&nbsp;&nbsp;var one = IsFormComplete(frmUser);<BR>&nbsp;&nbsp;&nbsp;&nbs p;var two = VerifyData();<BR>&nbsp;&nbsp;&nbsp;&nbsp;return one && two;<BR>}<BR><BR>The advantage of doing that is that both the functions are *always* called (assuming that&#039s what you want).<BR><BR>Plus you can easily add other validation functions if you need to, later.<BR>

  3. #3
    Steve Cimino Guest

    Default RE: OnSubmitting multiple Functions

    Don&#039t use & to in JavaScript for what you&#039re doing.. it is a bitwise AND operator, and I&#039m sure that&#039s not what you want. Use the logical AND (&&) and you may get your desired results.

  4. #4
    Nurice Guest

    Default Thank you all so much!

    Thanks- I knew it was simple. I appreciate it!

Posting Permissions

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