473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 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 3289
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Sam | last post by:
Hi, I can use System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory() to obtain the path for ILASM.exe, but how can I obtain the path to ILDASM.exe? Examples of the path I'm...
4
by: Rithish | last post by:
Is there a way to obtain the height of a <SELECT> element dynamically, i.e. through javascript? I want to dynamically display a list box onFocus of a text box element. Also, if the list box...
3
by: gooderthanyou | last post by:
I have a textfield and you of course you can select text... When they hit the bold button I want it to obtain the selected text and bold it, the hard part is trying to figure out if javascript...
3
by: Max Speransky | last post by:
Hello My task is to validate expression and get value of it in boolean variable. I try to do following: CREATE OR REPLACE FUNCTION get_value(integer) RETURNS boolean AS' DECLARE Ret ...
3
by: Eliu Montoya | last post by:
Hello everybody, Does anyone know an easy way to insert a record (without a value for the primary key because it is a sequence) and at the same time obtain the value of primary key that was...
14
by: Lauren Wilson | last post by:
Discovered this interesting comment on MSDN: "To programmatically obtain the hard disk's serial number that the manufacturer assigns, use the Windows Management Instrumentation (WMI)...
1
by: Yaro | last post by:
Hi How obtain server (machine name) with db2 8.1.5 ? I need get this name in select statement: select (something) from sysibm.sysdummy1 Would be nice also obtain fixpack level.
2
by: ME | last post by:
How would one obtain the parameter VALUES of a method that has already run? I can find the method using the StackTrace and StackFrame classes but once I find the method I would like to obtain the...
0
by: html | last post by:
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.