Joshua Davis
Joshua Davis

Reputation: 13

Are multiple onsubmit javascript functions allowed in a forms?

Are multiple onsubmit functions allowed in forms? Example:

<form name="form" method="POST" action="contactus.asp" onsubmit="return verify()" 
<!--*****CAN I ADD ANOTHER onsubmit FUNCTION HERE?***** -->>

Upvotes: 1

Views: 12075

Answers (2)

Adam Zalcman
Adam Zalcman

Reputation: 27233

Well, you can add any legal JavaScript statement including this:

<form onsubmit="return verify1() && verify2()">

or this

<form onsubmit="return verify1() || verify2()">

or more complex expressions which can include multiple function calls. Note that standard evaluation rules apply including short-circuit evaluation of logical expressions.

Upvotes: 4

Tango Bravo
Tango Bravo

Reputation: 3309

I believe that wouldn't work. You should just make a wrapper function, and include the functions which you desire to execute, inside of that.

<script type="text/javascript">
    var run1 = function() { alert("first"); }
    var run2 = function() { alert("second"); }

    function sub() {
        run1();
        run2();
    }
</script>
<form name="form" method="POST" action="contactus.asp" onsubmit="javascript:sub();">

Upvotes: 0

Related Questions