I have a simple question and I can''t find an answer for! Driving me nuts. I have a select list: <select name=''lista'' id=''lista'' size=''5''> <option value=''1''>1</option> <option value=''2''>2</option> <option value=''3''>3</option> </select> I want to iterate through all the options in the select. Now, I can do a generic for loop but that''s no fun. When I try: $(''lista'').options.each() I get an error about each() not being a function even though $ (''lista'').options is an array. Can I convert it to an enumerable object somehow? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Tom Gregory
2007-Sep-10 23:51 UTC
Re: Prototype - Convert list menu options into an enumerable?
"options" is not an Array, but a built-in object. Use $A() to perform the conversion. $A($(''lista'').options).each(function (v) {console.log(v);}); TAG On Sep 10, 2007, at 5:09 PM, FishGills wrote:> > I have a simple question and I can''t find an answer for! Driving me > nuts. > > I have a select list: > > <select name=''lista'' id=''lista'' size=''5''> > <option value=''1''>1</option> > <option value=''2''>2</option> > <option value=''3''>3</option> > </select> > > I want to iterate through all the options in the select. Now, I can do > a generic for loop but that''s no fun. > > When I try: > > $(''lista'').options.each() > > I get an error about each() not being a function even though $ > (''lista'').options is an array. > > Can I convert it to an enumerable object somehow? > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---