472,983 Members | 2,805 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,983 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 3275
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: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.