I want to get at the option value and the text within the options....i have this: var forms = $$(''select''); forms.each(function(select, index) { var opts = select.descendents; }) i think it has something to do with descendents but i''m not sure. Thanks :) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Why not just do something like this: var options = $$("select option"); Which would give you a list of all the options in the page. If you need to single out a specific select list, give it or its form an ID attribute and use it to limit the returned elements from $$(). Alternatively, you could loop through the options array using up("select") to determine the parent list for each option as necessary. Regardless, once you get the options, you can use their innerHTML property to get at the text and the readAttribute() function to extract their value. There could be a value property for option elements, though, which would avoid the need to read the value attribute, but I''m not sure on that one. - Dash - On Jan 24, 6:23 am, elduderino <jamesfiltn...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> I want to get at the option value and the text within the options....i > have this: > > var forms = $$(''select''); > forms.each(function(select, index) { > var opts = select.descendents; > > }) > > i think it has something to do with descendents but i''m not sure. > > Thanks :)--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Aha i see. So my current code ( in normal javascript) works by getting all the selects on a page and the iterates over them. //this function finds all the selects and passes them by reference on to selectReplacement() function setForm() { var s = document.getElementsByTagName(''select''); for (var i=0; i<s.length; i++) { selectReplacement(s[i]); } } //this function does the swapping of selects for un-ordered lists function selectReplacement(obj) { var opts = obj.options; for (var i=0; i<opts.length; i++) { //and so on What i wanted to do is for each of the selects get all the options out....is there no way to do this even though i have a reference to the select in ''select''......It seems a little verbose to get all the options out then find out which select they belong to.. On Jan 24, 3:03 pm, dashifen <dashi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Why not just do something like this: > > var options = $$("select option"); > > Which would give you a list of all the options in the page. If you > need to single out a specific select list, give it or its form an ID > attribute and use it to limit the returned elements from $$(). > Alternatively, you could loop through the options array using > up("select") to determine the parent list for each option as > necessary. > > Regardless, once you get the options, you can use their innerHTML > property to get at the text and the readAttribute() function to > extract their value. There could be a value property for option > elements, though, which would avoid the need to read the value > attribute, but I''m not sure on that one. > > - Dash - > > On Jan 24, 6:23 am, elduderino <jamesfiltn...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > > > I want to get at the option value and the text within the options....i > > have this: > > > var forms = $$(''select''); > > forms.each(function(select, index) { > > var opts = select.descendents; > > > }) > > > i think it has something to do with descendents but i''m not sure. > > > Thanks :)--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Sure, you can do that. Here''s an example: $$("select").each(function(list) { var options = list.select("option"); ... }); In that example, you get all the select elements and, which are referred to by the variable "list" within the anonymous function. Then, the Prototype Element.select() function can be used to get all of the options within each list. - Dash - On Jan 24, 9:34 am, elduderino <jamesfiltn...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> Aha i see. So my current code ( in normal javascript) works by getting > all the selects on a page and the iterates over them. > > //this function finds all the selects and passes them by reference on > to selectReplacement() > function setForm() { > var s = document.getElementsByTagName(''select''); > for (var i=0; i<s.length; i++) { > selectReplacement(s[i]); > } > } > > //this function does the swapping of selects for un-ordered lists > function selectReplacement(obj) { > var opts = obj.options; > for (var i=0; i<opts.length; i++) { > //and so on > > What i wanted to do is for each of the selects get all the options > out....is there no way to do this even though i have a reference to > the select in ''select''......It seems a little verbose to get all the > options out then find out which select they belong to.. > > On Jan 24, 3:03 pm, dashifen <dashi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Why not just do something like this: > > > var options = $$("select option"); > > > Which would give you a list of all the options in the page. If you > > need to single out a specific select list, give it or its form an ID > > attribute and use it to limit the returned elements from $$(). > > Alternatively, you could loop through the options array using > > up("select") to determine the parent list for each option as > > necessary. > > > Regardless, once you get the options, you can use their innerHTML > > property to get at the text and the readAttribute() function to > > extract their value. There could be a value property for option > > elements, though, which would avoid the need to read the value > > attribute, but I''m not sure on that one. > > > - Dash - > > > On Jan 24, 6:23 am, elduderino <jamesfiltn...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > > > > I want to get at the option value and the text within the options....i > > > have this: > > > > var forms = $$(''select''); > > > forms.each(function(select, index) { > > > var opts = select.descendents; > > > > }) > > > > i think it has something to do with descendents but i''m not sure. > > > > Thanks :)--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Oh! one other thing: the Element.select() function is only available since Prototype 1.6.0. If you''re using an earlier version you''ll probably need to use the getElementsByTagName() function instead. - Dash - On Jan 24, 1:06 pm, dashifen <dashi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Sure, you can do that. Here''s an example: > > $$("select").each(function(list) { > var options = list.select("option"); > > ... > > }); > > In that example, you get all the select elements and, which are > referred to by the variable "list" within the anonymous function. > Then, the Prototype Element.select() function can be used to get all > of the options within each list. > > - Dash - > > On Jan 24, 9:34 am, elduderino <jamesfiltn...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > > > Aha i see. So my current code ( in normal javascript) works by getting > > all the selects on a page and the iterates over them. > > > //this function finds all the selects and passes them by reference on > > to selectReplacement() > > function setForm() { > > var s = document.getElementsByTagName(''select''); > > for (var i=0; i<s.length; i++) { > > selectReplacement(s[i]); > > } > > } > > > //this function does the swapping of selects for un-ordered lists > > function selectReplacement(obj) { > > var opts = obj.options; > > for (var i=0; i<opts.length; i++) { > > //and so on > > > What i wanted to do is for each of the selects get all the options > > out....is there no way to do this even though i have a reference to > > the select in ''select''......It seems a little verbose to get all the > > options out then find out which select they belong to.. > > > On Jan 24, 3:03 pm, dashifen <dashi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Why not just do something like this: > > > > var options = $$("select option"); > > > > Which would give you a list of all the options in the page. If you > > > need to single out a specific select list, give it or its form an ID > > > attribute and use it to limit the returned elements from $$(). > > > Alternatively, you could loop through the options array using > > > up("select") to determine the parent list for each option as > > > necessary. > > > > Regardless, once you get the options, you can use their innerHTML > > > property to get at the text and the readAttribute() function to > > > extract their value. There could be a value property for option > > > elements, though, which would avoid the need to read the value > > > attribute, but I''m not sure on that one. > > > > - Dash - > > > > On Jan 24, 6:23 am, elduderino <jamesfiltn...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > > > > > I want to get at the option value and the text within the options....i > > > > have this: > > > > > var forms = $$(''select''); > > > > forms.each(function(select, index) { > > > > var opts = select.descendents; > > > > > }) > > > > > i think it has something to do with descendents but i''m not sure. > > > > > Thanks :)--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hi, Yes that works perfectly...thanks. Yes i''m on Prototype 1.6 so it''s ok On Jan 24, 7:08 pm, dashifen <dashi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Oh! one other thing: the Element.select() function is only available > since Prototype 1.6.0. If you''re using an earlier version you''ll > probably need to use the getElementsByTagName() function instead. > > - Dash - > > On Jan 24, 1:06 pm, dashifen <dashi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Sure, you can do that. Here''s an example: > > > $$("select").each(function(list) { > > var options = list.select("option"); > > > ... > > > }); > > > In that example, you get all the select elements and, which are > > referred to by the variable "list" within the anonymous function. > > Then, the Prototype Element.select() function can be used to get all > > of the options within each list. > > > - Dash - > > > On Jan 24, 9:34 am, elduderino <jamesfiltn...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > > > > Aha i see. So my current code ( in normal javascript) works by getting > > > all the selects on a page and the iterates over them. > > > > //this function finds all the selects and passes them by reference on > > > to selectReplacement() > > > function setForm() { > > > var s = document.getElementsByTagName(''select''); > > > for (var i=0; i<s.length; i++) { > > > selectReplacement(s[i]); > > > } > > > } > > > > //this function does the swapping of selects for un-ordered lists > > > function selectReplacement(obj) { > > > var opts = obj.options; > > > for (var i=0; i<opts.length; i++) { > > > //and so on > > > > What i wanted to do is for each of the selects get all the options > > > out....is there no way to do this even though i have a reference to > > > the select in ''select''......It seems a little verbose to get all the > > > options out then find out which select they belong to.. > > > > On Jan 24, 3:03 pm, dashifen <dashi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Why not just do something like this: > > > > > var options = $$("select option"); > > > > > Which would give you a list of all the options in the page. If you > > > > need to single out a specific select list, give it or its form an ID > > > > attribute and use it to limit the returned elements from $$(). > > > > Alternatively, you could loop through the options array using > > > > up("select") to determine the parent list for each option as > > > > necessary. > > > > > Regardless, once you get the options, you can use their innerHTML > > > > property to get at the text and the readAttribute() function to > > > > extract their value. There could be a value property for option > > > > elements, though, which would avoid the need to read the value > > > > attribute, but I''m not sure on that one. > > > > > - Dash - > > > > > On Jan 24, 6:23 am, elduderino <jamesfiltn...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > > > > > > I want to get at the option value and the text within the options....i > > > > > have this: > > > > > > var forms = $$(''select''); > > > > > forms.each(function(select, index) { > > > > > var opts = select.descendents; > > > > > > }) > > > > > > i think it has something to do with descendents but i''m not sure. > > > > > > Thanks :)--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---