I have a btn
<a href="#" id="submitBtn" class="btnGray">Upload Docs</a>
and a jquery code to submit the form.
$("#docSaveBtn").click(function(){
$("#docForm").submit();
});
I have multiple forms on the same page and I want to send the form id to submit which will submit the desired form when click of button with class ‘btnGray’.
Your help is highly appreciated.
Custom data attributes
One ideal solution would be to use custom data attributes on the anchor itself, informing jQuery which form should be submitted when the anchor is clicked.
In the above example, we’re stating that we would like our anchor to have an association with our form that immediately follows. Now we provide the logic via jQuery:
Example: http://jsfiddle.net/65HPj/
Proximity-based Submission…
A much cleaner solution would be proximity-based, where a link submits it’s closest form: