开发者

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"  &开发者_如何学JAVAgt; Reject Version </html:submit></td>

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

Please suggest some good examples.


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>


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.


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


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

functionA() {}
functionB() {}


Put all onclick events inside the validateText().

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜