Connecting Tech Pros Worldwide Forums | Help | Site Map

How do I obtain the value of Select?

html
Guest
 
Posts: n/a
#1: Sep 26 '08
I have a select tag as follows

<SELECT ID="Select1" NAME="Select1" ONCHANGE="do_alert()">
<OPTION>1</OPTION>
<OPTION>2</OPTION>
</SELECT>

I need, when the user choose an option, to print an alert
which displays the text in the option chosen, i.e. 1 or 2
in this example, but how do I access the value of the html
select tag, I tried

alert(document.getElementById('Select1').value);

But this seems to be an empty alert box. Any ideas what might I be
doing wrong?

Tia



Jukka K. Korpela
Guest
 
Posts: n/a
#2: Sep 26 '08

re: How do I obtain the value of Select?


html wrote:
Quote:
I have a select tag as follows
>
<SELECT ID="Select1" NAME="Select1" ONCHANGE="do_alert()">
<OPTION>1</OPTION>
<OPTION>2</OPTION>
</SELECT>
HTML-wise (i.e., from the perspective we are supposed to have in this
group), that construct has more problems than I care to list down. This is
probably not your _real_ select element, is it?
Quote:
I need, when the user choose an option, to print an alert
which displays the text in the option chosen,
That's external to HTML, of course, hence off-topic in this group. Your use
of the fake name "html" does not change that.
Quote:
but how do I access the value of the html
select tag, I tried
>
alert(document.getElementById('Select1').value);
We could tell you, but that would be off-topic and would teach you wrong
habits, like posting to a wrong group and not reading the fine manual. So
consider reading a tutorial on the basics of an introduction to the elements
of JavaScript in the web context before trying to use JavaScript on the web.

--
Yucca, http://www.cs.tut.fi/~jkorpela/

Jonathan N. Little
Guest
 
Posts: n/a
#3: Sep 26 '08

re: How do I obtain the value of Select?


Jukka K. Korpela wrote:
Quote:
html wrote:
>
Quote:
>I have a select tag as follows
>>
><SELECT ID="Select1" NAME="Select1" ONCHANGE="do_alert()">
><OPTION>1</OPTION>
><OPTION>2</OPTION>
></SELECT>
>
HTML-wise (i.e., from the perspective we are supposed to have in this
group), that construct has more problems than I care to list down. This
is probably not your _real_ select element, is it?
>
Quote:
>I need, when the user choose an option, to print an alert
>which displays the text in the option chosen,
>
That's external to HTML, of course, hence off-topic in this group. Your
use of the fake name "html" does not change that.
>
Quote:
>but how do I access the value of the html
>select tag, I tried
>>
>alert(document.getElementById('Select1').value) ;
>
We could tell you, but that would be off-topic and would teach you wrong
habits, like posting to a wrong group and not reading the fine manual.
So consider reading a tutorial on the basics of an introduction to the
elements of JavaScript in the web context before trying to use
JavaScript on the web.
>
As I recall MSIE will not automatically transfer the enclosed content of
an option element to its value attribute. You must implicitly define it
in your markup:
<SELECT ID="Select1" NAME="Select1"
ONCHANGE="alert(document.getElementById('Select1') .value)">
<OPTION VALUE="1">1</OPTION>
<OPTION VALUE="2">2</OPTION>
</SELECT>


--
Take care,

Jonathan
-------------------
LITTLE WORKS STUDIO
http://www.LittleWorksStudio.com
Lars Eighner
Guest
 
Posts: n/a
#4: Sep 26 '08

re: How do I obtain the value of Select?


In our last episode, <48dd055a$1_3@mk-nntp-2.news.uk.tiscali.com>, the
lovely and talented html broadcast on comp.infosystems.www.authoring.html:
Quote:
I have a select tag as follows

The answer is the same as the last time you posted this.

--
Lars Eighner <http://larseighner.com/usenet@larseighner.com
This would be the best of all possible worlds,
if there were no religions in it. -- John Adams
Closed Thread