...

View Full Version : Broken under new MSIE version



BobW
12-20-2010, 11:49 PM
The latest version of MSIE fails to read the value of a popup menu in a form that I have. It worked fine in a previous version, and works in Firefox and Mac Safari. Here is an edited version of what I have:


var d = null;

function myTest(){
alert("mWunits value = ".concat(d.mWunits.value))
}
.
.
.
<body onload="d = document.forms[0];">
.
.
.
<form onsubmit="return false" >
<table align="center" border="0">
<tbody>
<tr>
<td align="right">Conductor Size (d):</td>
<td><input name="ef_dw" size="12"> </td>
<td align="left">
<select name="mWunits" size="1">
<option selected="selected">mm</option>
<option>AWG</option>
</select>
</td>
</tr>
.
.
.

The popup name is mWunits, and should have either "AWG" or "mm" as a value. And the function myTest() should display that value. However the value is an empty string. There is another popup in the same form, and it exhibits the same problem. My script reads the values of regular input fields just fine. As I said, this used to work under earlier MSIE versions, and works in other browsers. Has something been deprecated that I don't know about?

longman
12-21-2010, 12:17 AM
Try assigning values to the menu options:



<select name="mWunits" size="1">
<option selected="selected" value="mm" >mm</option>
<option value="AWG" >AWG</option>
</select>

BobW
12-21-2010, 01:29 AM
Thanks. That fixed it. I'm confused though. According to the info I've read, if you don't explicitly assign a value, it should use the option element's contents by default. I guess I shouldn't take anything for granted.

Also confusing: I have a similar form on another page, where the popups are nearly the same, but they work as intended. The only difference that I can see is that the working ones also have an onchange="doSomething()" function assigned, although the function doesn't set the value; it only reads it.

Oh well, I guess from now on, I'll have to explicitly assign a value for each option.

longman
12-21-2010, 02:17 AM
Glad it's sorted. As a general rule when working with IE, I never take anything for granted!

Philip M
12-21-2010, 07:29 AM
Oh well, I guess from now on, I'll have to explicitly assign a value for each option.

In IE an option value must be assigned explicitly - the option text is not the value.



<select id = "mySelect" onchange = "getIt()">
<option>Volvo</option>
<option>Saab</option>
<option>Mercedes</option>
<option>Audi</option>
</select>


<script type = "text/javascript">
function getIt() {
var val = document.getElementById("mySelect").value;
alert (val);
var si = document.getElementById("mySelect").selectedIndex;
alert (si);
var txt = document.getElementById("mySelect").options[si].text;
alert (txt);
}
</script>

Kor
12-21-2010, 11:24 AM
I'm confused though. According to the info I've read, if you don't explicitly assign a value, it should use the option element's contents by default. I guess I shouldn't take anything for granted.

It should. W3C Recommendations says so. But you should know, also, that MSIE does not follow always the W3C Recommendations, nor the ECMAScript standard.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum