Jquery Validation, Get button clicked in submitHandler()
javascript, jquery, jquery-validate
Solution
You have two `submit` buttons on your form so by the time you get to the `submitHandler` it's too late. If you want to know which button is clicked you'll have to capture that event ahead of time.
Change them both to `type="button"` so you can control the submit.
<button class="btn btn-primary" name="add" type="button">Submit</button>
<button class="btn btn-primary" name="prospect" type="button">Submit & Add prospect</button>
Then add this...
$('button[name="add"], button[name="prospect"]').on('click', function (e) {
e.preventDefault();
if ($('#myform').valid()) {
$(this).prop('disabled', 'disabled');
$('#myform').submit();
}
});
DEMO: http://jsfiddle.net/etHcZ/
Problem
I have two buttons on the from `type='Submit''` After the validation, in `submitHandler` I want to get which one of these button is clicked. And depending on this, i want to disable that button. Handler ``` $("#add_customer").validate({ rules: { name: { required: true }, annual_sales_weight: { required: true, number: true } }, errorClass: "help-inline", errorElement: "span", highlight: highlightJquery, unhighlight: Unhilight, submitHandler: function (form) { var btn = $(form).find('button'); disable(btn) sendAjaxRequest(url,data=form.serialize()); } }); ``` HTML ``` <button class="btn btn-primary" name="add" type="submit"> Submit</button> <button class="btn btn-primary" name="prospect" type="submit"> Submit & Add prospect</button> ```