views:

51

answers:

2

Hello. 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

A: 

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() {}).

PhilI
the button id is random generated by the server and there will be hundreds of them, so I can't create an own click function for each one of them. as I said there must be a better way to this, I'm just not getting it :P
Seerumi
I understand a bit better now, the simplest way is probably to make all the buttons part of a "submitbutton" class and still give them a unique id. That way you can use $(.submitbutton).click() and inside the click function do different things depending on the $(this).attr('id') - see @mamoo post below
PhilI
+1  A: 

$("#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');
});
mamoo
thanks! I think this solves my problem.
Seerumi