I have a .submit()
event set up for form submission. I also have multiple forms on the page, but just one here for this example. I\'d like to know which submi
Working with this excellent answer, you can check the active element (the button), append a hidden input to the form, and optionally remove it at the end of the submit handler.
$('form.form-js').submit(function(event){
var frm = $(this);
var btn = $(document.activeElement);
if(
btn.length &&
frm.has(btn) &&
btn.is('button[type="submit"], input[type="submit"], input[type="image"]') &&
btn.is('[name]')
){
frm.append('');
}
// Handle the form submit here
$('#form-js-temp').remove();
});
Side note: I personally add the class form-js
on all forms that are submitted via JavaScript.