[jQuery] Finding form tag wrapping around image
<div dir="ltr">Hi,
I had an image input to trigger a form submit for a download to Excel, but because it appears at the top of the page when you hit Enter the form doesnt submit, the Excel thing fires.
So I have changed my image input to a plain old image and need to find the form id that it sits in, so I can fire a submit on that form. the pages where this appears are usually 2 forms on the page, one at the top and one where this image is a child.
How do I find the id of the parent form?
The page looks kind of like this:<br clear="all">
<form name="SearchForm" id="SearchForm" action=....>
.. tables and content..
<pre id="line483">
<<span class="start-tag">img</span><span class="attribute-name"> src</span>=<span class="attribute-value">"/media/pics/site/excel.jpg" </span><span class="attribute-name">name</span>=<span class="attribute-value">"downloadToExcel" </span><span class="attribute-name">id</span>=<span class="attribute-value">"downloadToExcel"</span>><<span class="start-tag">input</span><span class="attribute-name"> name</span>=<span class="attribute-value">"Export" </span><span class="attribute-name">id</span>=<span class="attribute-value">"Export" </span><span class="attribute-name">type</span>=<span class="attribute-value">"hidden" </span><span class="attribute-name">value</span>=<span class="attribute-value">"0" </span><span class="error"><span class="attribute-name">/</span></span>></pre>
.. more tables and content..
<input type="submit"> and other buttons.
</form>
And I have tried:
$("#downloadToExcel").click(function(){
$("#Export").val(1);
alert( $(this).parents('form:first').attr('id')); // returns undefined
});
how do I find the parent form id?
Thanks!
--
Duncan Isaksen-Loxton
<a href="http://www.red5.com.au">http://www.red5.com.au</a>
</div>