I have a number of select form elements all with a class "extrainfo".
What I would like to do is to capture when the select form element is
changed and run a function passing the select form elements ID/Name.
What is the best way to do this?
$$('.extrainfo').Event.observe('change',myfuntction(id))
on 2008-06-24 15:03
on 2008-06-24 15:12
DollarDollar returns a collection of matched elements, so the best way
is:
$$('.extrainfo').each(function(element){
Event.observe(element, 'change', myfuntction(id))
});
http://prototypejs.org/api/enumerable/each
--
blog: www.lucaguidi.com
Pro-Netics: www.pro-netics.com
Sourcesense - making sense of Open Source: www.sourcesense.com
on 2008-06-24 15:47
Hi, Luca Guidi wrote: > DollarDollar returns a collection of matched elements, so the best way is: > $$('.extrainfo').each(function(element){ > Event.observe(element, 'change', myfuntction(id)) > }); > Top of my head and not tested, you could also use #invoke, which is simpler: $$('.extrainfo').invoke('observe', 'change', myfunction); Notice that you should not execute myfunction(), but pass reference to it to #observe method (unless myfunction(id) returns reference to a function). myfunction will be called with event as first parameter, so you will have to check Event.findElement() to check which <select> was changed, e.g: function myfunction(evnt) { //should alert id of changed <select> alert (Event.findElement(evnt).id); } See Enumerable#invoke docs for details. -- Regards, SWilk