Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Getting the value of a selected option
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
skunkbad  
View profile  
 More options Jul 7, 10:44 pm
From: skunkbad <iamsen...@gmail.com>
Date: Tue, 7 Jul 2009 19:44:55 -0700 (PDT)
Local: Tues, Jul 7 2009 10:44 pm
Subject: Getting the value of a selected option
I've got a standard select box with options, and the select box has an
id of "theme_choice"

I've found the following script online, but it isn't popping up an
alert when a selection is made:

$$('#theme_choice').each(function(elem){
                                if (elem.selected) alert(elem.text + ' ' + elem.value);
                });

Prototype is called just before this in the head area of the page. I'm
using the latest version RC3.

This is for a theme changer script on my website. I have a current
theme changer script, but I'm trying to play around with prototype.

I don't know if it is spam to put a link to my website or reference
it, so I won't, but the select box with options is really just a
standard form element. Nothing special.

Thanks for your help.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
T.J. Crowder  
View profile  
 More options Jul 8, 3:36 am
From: "T.J. Crowder" <t...@crowdersoftware.com>
Date: Wed, 8 Jul 2009 00:36:35 -0700 (PDT)
Local: Wed, Jul 8 2009 3:36 am
Subject: Re: Getting the value of a selected option
Hi,

> I've found the following script online, but it isn't popping up an
> alert when a selection is made:

You're not asking it to. :-)  You're asking it to pop up an alert if
something is selected at the moment you're calling that code; you
haven't hooked up an event handler.  To make it happen when something
is selected, you'll need to observe the 'change' event (probably).
You probably also want $('theme_choice') rather than $$
('#theme_choice')[1][2].  More here[3][4].

[1] http://prototypejs.org/api/utility/dollar
[2] http://prototypejs.org/api/utility/dollar-dollar
[3] http://prototypejs.org/api/element/observe
[4] http://prototypejs.org/api/event/observe

HTH,
--
T.J. Crowder
tj / crowder software / com
Independent Software Engineer, consulting services available

On Jul 8, 3:44 am, skunkbad <iamsen...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
ColinFine  
View profile  
 More options Jul 9, 9:36 am
From: ColinFine <colin.f...@pace.com>
Date: Thu, 9 Jul 2009 06:36:58 -0700 (PDT)
Local: Thurs, Jul 9 2009 9:36 am
Subject: Re: Getting the value of a selected option
Incidentally, (not answering your question, which TJ has done)

> $$('#theme_choice').each(function(elem){
>                                 if (elem.selected) alert(elem.text + ' ' + elem.value);
>                 });

"$$('#something')"

while valid, is almost always wrong. It says "give me a list of all
the elements with id 'something'". But by definition there can be only
one such element, so it is simpler to replace your code with

elem = $(''theme_choice');
if (elem.selected) ...

If you are using this because you have multiple entities with the same
id, then your page is not valid HTML, and browsers may not behave
identically with it.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google