How can I know that which submit button was clicked on submit the form.
HTML:
<button type="submit" name="add_in_queue" id="add_in_queue" value="add_in_queue">Queue</button>
<button type="submit" name="create_tran" id="create_tran" value="create_tran">Process</button>
JQUERY:
$('form#create_tran_form').on('submit',function(e){
var submit_value = $(this).attr('id');
alert(submit_value);
e.preventDefault();
});
I am getting the form ID that is: create_tran_form. I want to get submit button's name or value. How can I achieve this?
Thanks.
There is no way to tell from the submit event. You need to capture the event on the button.
e.g. have an event handler that listens for submit button clicks, store the result on the form, then read it back in on your submit handler.
$('[type="submit"]').on('click', function (evt) {
$(this.form).data('selected', this.value);
});
$('form').on('submit', function (evt) {
alert($(this).data('selected'));
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With