ajax - JQuery - which form was submitted? -
i have page of products , each of them, want have form uses ajax update session. i've done bit - providing background.
i use product's id create different form class , name each form, each form called this_form_name_567
, next this_form_name_568
, on.
there submit button per form. i'm having trouble figuring out
which event best use correct form identified when submit button clicked?
once clicked, how make sure correct value taken hidden field (unique id) within submitted form can populate line of code such as:
$.post("compare_response.php", {compare_this: $("#compare_this").val()}, function(data){ }
you can use .closest
tree traversal method form in button of interest nested:
$("input[type=submit]").click(function() { alert($(this).closest("form").attr("id")); });
or simpler, element's form
property :)
$("input[type=submit]").click(function() { alert(this.form.id); });
Comments
Post a Comment