problems with IE and select/option value

S

steve cole

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
 
I

Ivo

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).
<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
 
S

steve cole

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,262
Messages
2,571,059
Members
48,769
Latest member
Clifft

Latest Threads

Top