I am having a bit of an issue with a form that has multiple submission buttons on it. What I want it to do is when the form is submitted, it will read the value of the button that was clicked and then put that value into a hidden field. What it is currently doing is when either search button is hit it reads the first submission button listed in the document and not necessarily the button that was clicked. Anyone know how to modify it so it actually reads the button that is hit instead of the first one listed? <input name="submitForm" type="submit" class="button_class" value="Search 1"> <input name="submitForm" type="submit" class="button_class" value="Search 2"> HTML: $(document).ready(function(){ $("#product").submit(function(){ $('input[name=form_id]').val($('.button_class').val()); $.ajax({ type: "POST", url: "access.php", data: $("#product").serialize(), dataType: "json", success: function(msg){ $('#formResponse').html(msg.message); }, error: function(){ $('#formResponse').text("There was an error submitting the form. Please try again."); } }); //make sure the form doesn't post return false; }); }); Code (markup):
you can't add 2 submit buttons for a form, but you may do something like this if you going to make it with ajax requests and return false when buttons clicked <input name="submitForm" type="submit" class="button_class" value="Search 1" [COLOR=#ff0000]id="button1"[/COLOR]> <input name="submitForm" type="submit" class="button_class" value="Search 2" [COLOR=#ff0000]id="button2"[/COLOR]> Code (markup): jQuery: $(function(){ $("#button1").click( function(){ // do something when first button is clicked // maybe your ajax request here return false; // Important! }); $("#button2").click( function(){ // do something when first button is clicked // maybe your ajax request here return false; // Important! }); }); Code (markup):