473,408 Members | 1,786 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,408 software developers and data experts.

problems with IE and select/option value

Hi All

No doubt I am doing something stupid since i am new to javascript

I have a problem with the following code, when run on IE6 the value for
opt_sel is null but on Mozilla or konqueror the value is the option
selected (as expected). I have tried several books on the matter(and
google), but they seem to indicate that what i am trying to do should
work... Very annoying!
I have made the script as simple as possible to illustrate my problem.
please help, this is driving me crazy!!!!

<html>
<head>

<script language=JavaScript type=text/javascript>
function check_form(){
alert (document.form1.opt_sel.value)
}
</script>
</head>

<body>
<form name=form1 id=form1>
<select name="opt_sel" id="opt_sel">
<option selected>opt1</option>
<option>opt 2</option>
<option>opt 3</option>
</select>

<input name="submit" value="submit" type="submit" onclick=check_form()>

</form>
</body>
</html>
Thanks

Steve
Jul 23 '05 #1
2 1639
Ivo
"steve cole" wrote
I have a problem with the following code, when run on IE6 the value for
opt_sel is null but on Mozilla or konqueror the value is the option
selected (as expected). <snip> <script language=JavaScript type=text/javascript>
Don't use the language attribute, no browser needs it. Put quotes around the
type value. It is good habit to always put values in quotes, when there are
weird characters (such as the slash), they are required.
function check_form(){
alert (document.form1.opt_sel.value)
alert (document.form1.opt_sel[document.form1.opt_sel.selectedIndex].text)
The options in your code don't have values, so I alert the text.
HTH
Ivo
}
</script>
</head>

<body>
<form name=form1 id=form1>
<select name="opt_sel" id="opt_sel">
<option selected>opt1</option>
<option>opt 2</option>
<option>opt 3</option>
</select>

<input name="submit" value="submit" type="submit" onclick=check_form()>

</form>
</body>
</html>
Thanks

Steve

Jul 23 '05 #2
On Thu, 01 Jul 2004 23:31:21 +0200, Ivo wrote:
function check_form(){
alert (document.form1.opt_sel.value)


alert (document.form1.opt_sel[document.form1.opt_sel.selectedIndex].text)
The options in your code don't have values, so I alert the text.
HTH
Ivo

Thanks
That did the job.
Steve

Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Eric | last post by:
Hey Everyone.. I have a form that has approximately 7 text fields and 1 checkbox. Generally when this form is submitted(to itself BTW) it works fine, however, when the checkbox is only field...
0
by: Christopher Brandsdal | last post by:
Hi! I have a anoying problem with my editor! What i want to do is make a popup that holds a string for the "hyperlink" window... I have a popup to do this before, and it works perfecty, but in...
0
by: Michael Fork | last post by:
Note: I pasted the code the attachments as plain text after the message (I wasn't able to post it with an attachment...) Attached are the XSL and XML files that I am having problems with. I am...
3
by: daveland | last post by:
I am working on some JavaScript that dynamically adds rows to a table in response to a button click. A new row does appear on the screen when the button is clicked. However, that table to which a...
5
by: Shawn Modersohn | last post by:
For the script: <script language="JavaScript"> function pullPage(){ var arrayLength=document.teamSelectionF.teamSelectionS.length; var pageNav = new Array(arrayLength); var...
11
by: brian.newman | last post by:
I'm trying to use a layer inside a form to hide/reveal a part of the form, but my code doesn't seem to be working and I need some help debugging it. I'm not getting an error which has made it...
6
by: Omar | last post by:
Hi, In a JSP I have the next: .... codigo = "<select name='" + nombre + "'>\n<option selected value='default'>Escoge</option><option value='todos'>Todos</option>"; if (miRS != null) while...
9
by: please-answer-here | last post by:
What is wrong with this code? when i place "return false" before the xfab assignment the form as intended doesn't submit. But when placed as here or in the last if/else construct the page gets...
2
by: cbjewelz | last post by:
Hey all. So I'm having problems with cross browser alignments. I'm looking at Safari and Mozilla Firefox. I develop in Safari and so it looks perfect there however in Firefox my vertical...
3
by: dtvuser | last post by:
Hi, I'm new to PHP and seem to be having soom problems, I'm getting confused with all the different styles of script writing. I've created a PHP script to submit details to my email but the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.