Reputation: 1541
This is a JavaScript question.
Given the following code:
<input type="button" name="applyFilter" value="Apply Filter" onClick="doSubmit('applyFilter')"/>
function doSubmit(action) {
f=document.forms[0];
f.action=action;
f.submit();
}
How can I obtain the form object of the button clicked within doSubmit()? Currently, you see a reference to forms[0] but I want this to work with multiple forms on the page and I do not want to pass in the form name/id/reference or the button object reference. The button is on a form and I hope doSubmit(action) function can get that form object.
Upvotes: 1
Views: 3481
Reputation: 147363
If you attach the listener dynamically you can use the related event object. There is no way to do it otherwise in a cross-browser way (IE has window.event but that isn't W3C compatible or supported by a good percentage of commonly used browsers).
Upvotes: 1
Reputation: 6761
using jQuery
$('input[type="button"]').on('click',function(){
$(this).parents('form').submit();
})
Upvotes: 0
Reputation: 91
Maybe you can try 'bubble' of event. I mean you can use event.target or event.srcElement.
Upvotes: 0