krishna
krishna

Reputation: 179

Example showing how to write two onclick() events for a single html:button in jsp page

<td colspan="2" align="center"><html:submit onclick= "return validateText()"
            styleId="reject"  > Reject Version </html:submit></td>

I want to write one more onclick event for this button.

Please suggest some good examples.

Upvotes: 1

Views: 8037

Answers (5)

Waleed A.K.
Waleed A.K.

Reputation: 1656

Put all onclick events inside the validateText().

function validateText(){
  onclick_1();
  onclick_2();
....
   onclick_N();
}

Upvotes: 0

Tomas Narros
Tomas Narros

Reputation: 13468

You could try to add a function encapsulating both calls:

<script>
  function myEventHandler() {
      if(validateText()) {
          theSecondFunction();
          return true;
      }
      return false;
  }
</script>

And call it from your button:

<td colspan="2" align="center"><html:submit onclick= "return myEventHandler()"
            styleId="reject"  > Reject Version </html:submit></td>

Upvotes: 1

Kris Krause
Kris Krause

Reputation: 7326

function validateText() {
   // Call functionA
   // Call functionB
}

functionA() {}
functionB() {}

Upvotes: 0

Brissles
Brissles

Reputation: 3891

You can't add two OnClick events for a single element.

Upvotes: 0

jgallant
jgallant

Reputation: 11273

Just make the validateText() function call another function. The event will fire once, and you can do what you want at that point. You cannot bind two onclick events on the same button, if that is what you are trying to do.

Upvotes: 0

Related Questions