Seerumi
Seerumi

Reputation: 2037

jQuery: how to pick unique IDs?

New to whole this jQuery (and javascript altogether, heh) and so far it's been excellent, but now I'm in a small pickle. Let's say I have list of forms generated from SQL database and every single one of them has to have unique id, so how I can select the specific item that is to be manipulated (changing values via php).

the $("#submit").click(function()) will trigger every submit buttons on the page, so how I can the #submit to be some random id that I clicked. There might be a smarter way, but I'm new to this so try to bear with me.

thought of passing the unique value with onClick="myfunction(unique_id)", but don't know how it goes with jQuery.

hope this made any sense

Upvotes: 2

Views: 454

Answers (2)

mamoo
mamoo

Reputation: 8166

$("#submit") won't intercept every submit button click, but only the element with id="submit".

If you want to get the form's id attribute you can use a snippet like this:

$("form").submit(function () { 
 var selectedFormID = $(this).attr('id');
});

Upvotes: 1

Phil
Phil

Reputation: 1110

I might not be understanding the question correctly but if each of the submit buttons has a unique id, e.g. <button id="submit_02">Submit</button> then the jQuery would be $("#submit_02").click(function() {}).

Upvotes: 0

Related Questions