2 Replies Latest reply on Apr 18, 2006 4:36 PM by Dan Bracuk

    onclick or onsubmit which is better?

    Level 1

      Adding JS validation onclick of a submit button or adding JS to form onsubmit, which is better?. What is Adv and Dis?.

      <form name="frm" method="post">
      <input type="Submit" name="Submit" value="Submit" onclick="return JSCheck(this.form)">


      <form name="frm" method="post" onsubmit="return JSCheck(this.form)">
      <input type="Submit" name="Submit" value="Submit">


        • 1. Re: onclick or onsubmit which is better?
          BKBK Adobe Community Professional & MVP
          In this kind of programming there are no hard and fast rules. I don't think there is a significant difference between the two. Which one you choose depends on how creatively you put the function JSCheck() together.

          However, i prefer the second. I get the feeling the button is 'overloaded', as it has to respond to two events: submit the form and run the script.

          Also, if the Javascript performs form validation, then it will only be natural for it to be called by onSubmit. Imagine that the result of the form validation, return JSCheck(this.form), is a boolean. If it is true, the form is submitted; otherwise, not. In these circumstances the code onSubmit="true;" will be more natural than the code onClick="true;" .

          • 2. Re: onclick or onsubmit which is better?
            Dan Bracuk Level 5
            onsubmit is better because you can submit a form without clicking anything.