Reputation: 11
i am having Multiple forms, which contains input tag of type submit , i am using id=submit in all the forms
<form id='geek' method="post" action="#" role="form">
<input type="text" name="name" class="modal_input" id='name' placeholder="Only Alphabets Allowed" >
<input type="submit" name="submit" value="Submit" class="apply_button text-center center-block" id="submit" />
</form>
Second form
<form id='geek1' method="post" action="#" role="form">
<input type="text" name="name" id='name' placeholder="Only Alphabets Allowed" >
<input type="submit" name="submit" value="Submit" class="apply_button text-center center-block" id="submit" />
</form>
calling form1
$('#geek').validator();
$('#geek').on('submit', function (e) {
......
})
});
form 2
$('#geek1').validator();
$('#geek').on('submit', function (e) {
......
})
});
Element IDs should be unique, with this practice am i doing wrong?
Upvotes: 1
Views: 1755
Reputation: 1074335
Element IDs should be unique, with this practice am i doing wrong?
Yes, because you're using id="name"
on more than one input
element. It's fine to use name="name"
on more than one element, but it's not fine to use id="name"
on more than one element.
In terms of your forms, id="geek"
and id="geek1"
are different IDs, so there's no problem there.
Note that your "form 2" example used #geek1
in one place and #geek
in another, which is probably not what you wanted.
Having said that, do you really need id
s for these forms? How about:
$(".common-class-on-the-forms").validator().on("submit", function() {
// Use `this` here to refer to the specific form that was submitted
});
Upvotes: 4