Reputation: 3056
Hello I have a form which has two buttons. In the form validation (onsubmit callback), I would like to know which of the two submit buttons which both share the same name were clicked.
How can I do that using JQuery?
Upvotes: 2
Views: 171
Reputation: 10887
You can try:
$("form").submit(function() {
if ($(this).attr("id") == "some_id") {
// Do something ...
}
}
Upvotes: 1
Reputation: 8886
Jsfiddle Link
HTML
<input type="button" name="sameName" class="buttonClass" id="Button1" value="Button1">
<input type="button" name="sameName" class="buttonClass" id="Button2" value="Button2">
Jquery
$(".buttonClass").click(function(){
alert($(this).attr("id")+" clicked");
})
Upvotes: 2
Reputation: 1957
Use event.target
(assuming the callback's argument is called event.): http://api.jquery.com/event.target/
Upvotes: 0