views:

31

answers:

1

Hi Guys,

Im working on a project currently and really using javascript, Jquery / AJAX heavily for the first time and have run into an issue. Ill do my best to explain it but an example which has all the key parts can be found here

http://mail.diskbank.com.au:8080/kieran/AJAX-test.php

Basically i have a quote form where people can dynamically add fields to the form (see example add product button) , when its clicked it generates some new form field, each set of these form fields have their own number id so that it is named uniquely.

Part of this is that there two drop downs, one which when changes fetches results via AJAX for the second drop down. The problem i have is when more than one product added for it to return and update the checkbox for the correct product.

The only way i can really work out how to do this is when a product is added also add a new chuck of jquery that is watching the select box with that particular ID but that seems inefficient.

Is there a better way to do this??

If you need me to explain further let me know

Thanks in advance

+1  A: 

.live() seems to be what you need.

Plynx
Hey that looks like exactly what i need but the one thing i cannot work out is how to pass the ID of the element that was changed to the function. What would be the best way to do that to ensure that the data is loaded into the correct box??
kwhohasamullet
Sorry, Just figured out how to do itthankyou so much for your direction..i look everywhere for something to do this :D
kwhohasamullet
Glad to help ^_^ For others reading the question, the solution is to use `.live()` with a non-ID-based selector. Inside the handler, use `$(this)` to operate on the item that raised the event. For example, to get the ID (if you still need it), use `$(this).attr(‘id’)`.
Plynx