Having this form with this drop down menu:
<form id="form1" name="form1" method="post"
action="">
<select name="myList" id="myList">
<option value="1">item1</option>
<option value="2">item2</option>
<option value="3">item3</option>
<option value="4">item4</option>
</select>
<input type="button" name="test" id="test"
value="test"
onClick="alertSelected();">
</form>
If I wanted the value of the selected item, using Prototype, I''d have:
function alertSelected ()
{
alert ( $F(''myList'') );
}
What If I want the text?
This works, but it looks like a lot of work.
function alertSelected ()
{
alert ( document.form1.myList[$F(''myList'')].text);
}
Can''t this be simplified, taking advantage of Prototype?
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
David Dashifen Kees
2007-Jul-31 18:35 UTC
Re: grab text of selected item in drop down menu
Someone with more CSS knowledge than I have might be able to weight in,
but I wonder if something like this would work:
$$("#myList option:selected")[0].innerHTML
- Dave -
nunomira wrote:> Having this form with this drop down menu:
>
> <form id="form1" name="form1"
method="post" action="">
> <select name="myList" id="myList">
> <option value="1">item1</option>
> <option value="2">item2</option>
> <option value="3">item3</option>
> <option value="4">item4</option>
> </select>
> <input type="button" name="test" id="test"
value="test"
> onClick="alertSelected();">
> </form>
>
> If I wanted the value of the selected item, using Prototype, I''d
have:
> function alertSelected ()
> {
> alert ( $F(''myList'') );
> }
>
> What If I want the text?
>
> This works, but it looks like a lot of work.
>
> function alertSelected ()
> {
> alert ( document.form1.myList[$F(''myList'')].text);
> }
>
> Can''t this be simplified, taking advantage of Prototype?
>
>
> >
>
>
--~--~---------~--~----~------------~-------~--~----~
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,
Thanks for your reply.
I tested it but it always returns the first item: item1.
I''ve also noticed that my code
alert ( document.form1.myList[$F(''myList'')].text);
is wrong and doesn''t work.
This is working
id = document.form1.myList.selectedIndex;
myText = document.form1.myList[id].text;
alert(myText);
Maybe I''m looking at this the wrong way and shouldn''t try to
use
Prototype here.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
David Dashifen Kees
2007-Jul-31 19:54 UTC
Re: grab text of selected item in drop down menu
Yeah, I wouldn''t worry about prototype. This is more of a job for "normal" javascript. - Dash - nunomira wrote:> hi, > > Thanks for your reply. > > I tested it but it always returns the first item: item1. > > I''ve also noticed that my code > > alert ( document.form1.myList[$F(''myList'')].text); > > is wrong and doesn''t work. > > This is working > > id = document.form1.myList.selectedIndex; > myText = document.form1.myList[id].text; > alert(myText); > > Maybe I''m looking at this the wrong way and shouldn''t try to use > Prototype here. > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---