Pramil
Pramil

Reputation: 227

Finding the value Submit button onclick

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

Answers (3)

Zaheer Ahmed
Zaheer Ahmed

Reputation: 28548

Working Fiddle

try this:

$("input[type=submit]").click(function () {
    if ($(this).val() == "Close") alert("close clicked");
    if ($(this).val() == "Submit") alert("Submit clicked");    
});

Upvotes: 2

Arun P Johny
Arun P Johny

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

codingrose
codingrose

Reputation: 15699

Try:

$("input[type='submit']").submit(function(){
    alert($(this).val());
    return false;
});

Upvotes: 2

Related Questions