tags:

views:

11

answers:

1

How can I pass btnClicked variable via the submit trigger in order to know the button clicked.

$('div.btn_confirm li.cancel, div.btn_confirm li.save').click(function(e){
    var btnClicked = $(this).attr('class');//cancel or save
    $('form#my_form').submit();
});

$('form#my_form').submit(function() {
    var postData = $(this).serialize();
    $.post('process.php', postData+'&btnclicked='+btnClicked);
    return false;
});
+2  A: 

You could append a hidden field to your form:

<input type="hidden" name="btnClicked" id="btnClicked" value="some default value" />

And then set its value before submitting:

$('div.btn_confirm li.cancel, div.btn_confirm li.save').click(function(e){
    var btnClicked = $(this).attr('class');
    $('form#my_form #btnClicked').val(btnClicked);
    $('form#my_form').submit();
});

$('form#my_form').submit(function() {
    $.post('process.php', $(this).serialize());
    return false;
});
Darin Dimitrov