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

  1. which event best use correct form identified when submit button clicked?

  2. 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); }); 

you can try out here.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -