struts2 - How to suppress Jquery Validation submitHandler when cancel button is clicked? -


here have problem jquery validation plugin , struts2.

i have 3 buttons below in form.

<td><s:submit type="button" value="save" theme="simple" cssclass="valid" /></td> <td><s:submit type="button" value="cancel" theme="simple" action="cancel" cssclass="cancel"/></td> <td><s:submit type="button" value="submit" theme="simple" cssclass="valid"/></td> 

when form submitted, validations done using jquery validation. after form submitted, want user confirmation submit form ?

so used submithandler of jquery validate function. when click cancel submithandler getting executed. dont want happened when cancel button clicked. here javascript part.

$(document).ready(function() {      $("#myform").validate({     //some validation rules         submithandler: function(form) {         //this runs when form validated         //my code after submitting form              alert("hello");         } //end of submit handler     });  }); 

i know simple answer.though please me find people

the root problem form contains 3 submit buttons. though each 1 has different value, plugin trigger same on each one.

1) change cancel button type="reset". plugin ignore type of input (however, html clear form data).

http://jsfiddle.net/hnyd2/

or

2) move cancel button outside of form. layout different can place button more precisely using css.

http://jsfiddle.net/hnyd2/1/

or

3) leave inside form, block default behavior of submit button using jquery's preventdefault(). must put id on button can target properly.

$('#cancel').click(function(e) {     e.preventdefault();     // else on click }); 

http://jsfiddle.net/hnyd2/3/


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -