but i can''t seem to find the answer after about 45 minutes of googling
and
API browsing
i have a select
<select id="list">
<option value="0">Please Choose One:</option>
<option value="1">one</option>
<option value="2">two</option>
<option value="3">three</option>
<option value="4">four</option>
</select>
how do i get the actual text?
$F(''list'') returns 0 through 4
$(''list'').value returns 0 through 4
$(''list'').selectedIndex returns 0 through 4
i just can''t seem to stumble upon the one that will give me the actual
text...
any help would be cool.
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
-~----------~----~----~----~------~----~------~--~---
var list = $(''list''); list.options[list.selectedIndex];
?
On 8/29/07, Brian Williams
<brianw1975-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> but i can''t seem to find the answer after about 45 minutes of
googling and
> API browsing
>
> i have a select
>
> <select id="list">
> <option value="0">Please Choose One:</option>
> <option value="1">one</option>
> <option value="2">two</option>
> <option value="3">three</option>
> <option value="4">four</option>
> </select>
>
>
> how do i get the actual text?
>
> $F(''list'') returns 0 through 4
> $(''list'').value returns 0 through 4
> $(''list'').selectedIndex returns 0 through 4
>
> i just can''t seem to stumble upon the one that will give me the
actual
> text...
>
> any help would be cool.
>
> 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
-~----------~----~----~----~------~----~------~--~---
I cant speak for the other browsers but I think the actual property is innerText in ie... might be the same in others?> var list = $(''list''); > alert(list.options[list.selectedIndex].innerText); >Gareth On 8/30/07, Andrew Kaspick <akaspick-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > var list = $(''list''); list.options[list.selectedIndex]; > > ? > > On 8/29/07, Brian Williams <brianw1975-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > but i can''t seem to find the answer after about 45 minutes of googling > and > > API browsing > > > > i have a select > > > > <select id="list"> > > <option value="0">Please Choose One:</option> > > <option value="1">one</option> > > <option value="2">two</option> > > <option value="3">three</option> > > <option value="4">four</option> > > </select> > > > > > > how do i get the actual text? > > > > $F(''list'') returns 0 through 4 > > $(''list'').value returns 0 through 4 > > $(''list'').selectedIndex returns 0 through 4 > > > > i just can''t seem to stumble upon the one that will give me the actual > > text... > > > > any help would be cool. > > > > 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 -~----------~----~----~----~------~----~------~--~---
it''s actually quite easy:
$$(''#hobbies option'').find(function(el){return
el.selected}).value; //
returns value of selected option
-- 
View this message in context:
http://www.nabble.com/frustratingly-stupid-Select-question-tf4349554.html#a12396838
Sent from the RubyOnRails Spinoffs mailing list archive at Nabble.com.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
Okay...
The OP was actually about the option *text*, not the option *value*.
$F(''list'') should return the value(s) of the select
element''s
selected option(s). As does the following (the long way around):
$(''#hobbies option'').find(function(el){return
el.selected}).value;
list.options[list.selectedIndex]; // returns a reference to the  
selected option.
The innerText option (which someone suggested) is an IE-only thing.  
Won''t work on Mozilla, etc.
One thing to understand, is that if an option has no value attribute  
defined, the value should default to the option''s text. (The example  
problem provided had values specified, but you could leverage this  
characteristic if needed.)
Use either the "text" attribute of the option object (preferred), or  
innerHTML. There are a couple of ways of pulling this off. Here''s one:
$A($(''list'').options).findAll(function (o) {return
o.selected;}).pluck
(''text'');
TAG
On Aug 29, 2007, at 4:12 PM, kangax wrote:
>
>
> it''s actually quite easy:
>
> $$(''#hobbies option'').find(function(el){return
el.selected}).value; //
> returns value of selected option
> -- 
> View this message in context: http://www.nabble.com/frustratingly- 
> stupid-Select-question-tf4349554.html#a12396838
> Sent from the RubyOnRails Spinoffs mailing list archive at Nabble.com.
>
>
> >
--~--~---------~--~----~------------~-------~--~----~
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 from italy.
For my applications, i generally use:
$(''list'').options[$(''list'').selectedIndex].text
and it works on all browsers
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
On Aug 30, 9:24 am, Tom Gregory <t...-PGZyUNKar/Q@public.gmane.org> wrote: [...]> One thing to understand, is that if an option has no value attribute > defined, the value should default to the option''s text. (The example > problem provided had values specified, but you could leverage this > characteristic if needed.)But not in IE...> > Use either the "text" attribute of the option object (preferred), or > innerHTML. There are a couple of ways of pulling this off. Here''s one: > $A($(''list'').options).findAll(function (o) {return o.selected;}).pluck > (''text'');$(''list'').options[$(''list'').selectedIndex].text; seems somewhat shorter (though I''d probably use a local variable to store $(''list'')). -- Rob --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Yah, I forgot to add the .text in my response before. Wrote it from the top of my head... oops. On 8/29/07, nunziocastaldi <nunziocastaldi-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org> wrote:> > Hi from italy. > For my applications, i generally use: > > $(''list'').options[$(''list'').selectedIndex].text > > and it works on all browsers > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Aug 29, 2007, at 8:54 PM, RobG wrote:> On Aug 30, 9:24 am, Tom Gregory <t...-PGZyUNKar/Q@public.gmane.org> wrote: > [...] >> One thing to understand, is that if an option has no value attribute >> defined, the value should default to the option''s text. (The example >> problem provided had values specified, but you could leverage this >> characteristic if needed.) > > But not in IE...... unless one uses $F(), which glosses over browser quirks. =)>> Use either the "text" attribute of the option object (preferred), or >> innerHTML. There are a couple of ways of pulling this off. Here''s >> one: >> $A($(''list'').options).findAll(function (o) {return >> o.selected;}).pluck >> (''text''); > > $(''list'').options[$(''list'').selectedIndex].text; > > seems somewhat shorter (though I''d probably use a local variable to > store $(''list'')).''tis true. The difference? One returns all rows (which is useful for a multiple-select), the other, just the first selected row. Like I said, many different ways of doing it. =) TAG --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I use the following code to SET a select based upon value ...
Element.addMethods (''SELECT'', {
	selectValue : function(element, s_Value) {
		element = $(element);
		element.selectedIndex =
$A(element.options).pluck(''value'').indexOf(s_Value);
		return element;
		}
	}
);
With this, I can do
$(''selectID'').selectValue(''one'');
On 30/08/2007, Tom Gregory <tomg-PGZyUNKar/Q@public.gmane.org>
wrote:>
>
> On Aug 29, 2007, at 8:54 PM, RobG wrote:
>
> > On Aug 30, 9:24 am, Tom Gregory
<t...-PGZyUNKar/Q@public.gmane.org> wrote:
> > [...]
> >> One thing to understand, is that if an option has no value
attribute
> >> defined, the value should default to the option''s text.
(The example
> >> problem provided had values specified, but you could leverage this
> >> characteristic if needed.)
> >
> > But not in IE...
>
> ... unless one uses $F(), which glosses over browser quirks. =)
>
> >> Use either the "text" attribute of the option object
(preferred), or
> >> innerHTML. There are a couple of ways of pulling this off.
Here''s
> >> one:
> >> $A($(''list'').options).findAll(function (o)
{return
> >> o.selected;}).pluck
> >> (''text'');
> >
> >
$(''list'').options[$(''list'').selectedIndex].text;
> >
> > seems somewhat shorter (though I''d probably use a local
variable to
> > store $(''list'')).
>
> ''tis true.  The difference? One returns all rows (which is useful
for
> a multiple-select), the other, just the first selected row.
>
> Like I said, many different ways of doing it.  =)
>
>
> TAG
>
> >
>
-- 
-----
Richard Quadling
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
"Standing on the shoulders of some very clever giants!"
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
On 30/08/2007, Richard Quadling <rquadling-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> I use the following code to SET a select based upon value ... > > Element.addMethods (''SELECT'', { > selectValue : function(element, s_Value) { > element = $(element); > element.selectedIndex = $A(element.options).pluck(''value'').indexOf(s_Value); > return element; > } > } > ); > > With this, I can do > > $(''selectID'').selectValue(''one'');And I have an option whose value is -1 to allow for missing values. -- ----- Richard Quadling Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 "Standing on the shoulders of some very clever giants!" --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---