471,596 Members | 937 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,596 software developers and data experts.

How do I obtain the value of Select?

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
Sep 26 '08 #1
3 3225
html wrote:
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?
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.
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/

Sep 26 '08 #2
Jukka K. Korpela wrote:
html wrote:
>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?
>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.
>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
Sep 26 '08 #3
In our last episode, <48**********@mk-nntp-2.news.uk.tiscali.com>, the
lovely and talented html broadcast on comp.infosystems.www.authoring.html:
I have a select tag as follows

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

--
Lars Eighner <http://larseighner.com/us****@larseighner.com
This would be the best of all possible worlds,
if there were no religions in it. -- John Adams
Sep 26 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Rithish | last post: by
3 posts views Thread by gooderthanyou | last post: by
3 posts views Thread by Eliu Montoya | last post: by
1 post views Thread by Yaro | last post: by
reply views Thread by html | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.