I would like to select a input field from a form on the fly, which mean, I don’t know which form it would be. consider the following code: ( Suppose the input field id is always ‘input1’ across all forms)
$('[id^=myform]').submit(function(){
var formId = $(this).attr('id');
var result = $('#' + formId + ' input#inputl').val();
...
});
I am looking for a better solution for my purpose. Is there any?
You’d be better off using the
nameattribute of the element (having multiple elements with the same ID is invalid in HTML), and making sure those names are kept consistent across forms: