Reputation: 227
I have two button in my form
<input type="submit" name="_finish" id="_finish" value="Submit" class="butn" />
<input type="submit" name="_cancel" value="Close" class="butn" style="width:60px;"/>
I am trying to find which button is clicked.Searching on google I got jquery code like this
var val = $("input[type=submit][clicked=true]").val();
But alerting this value shows that this is undefined.How can I fulfil my goal.Any know help me
Upvotes: 1
Views: 107
Reputation: 28548
try this:
$("input[type=submit]").click(function () {
if ($(this).val() == "Close") alert("close clicked");
if ($(this).val() == "Submit") alert("Submit clicked");
});
Upvotes: 2
Reputation: 388316
You need to use the click handle as the submit event does not give info on which button was clicked
$("input[type=submit]").click(function(){
alert(this.value);
return false;
});
Demo: Fiddle
Upvotes: 1
Reputation: 15699
Try:
$("input[type='submit']").submit(function(){
alert($(this).val());
return false;
});
Upvotes: 2