This has already been logged as bug #440 (
http://jquery.com/dev/bugs/bug/440/)
On 11/29/06, Brice Burgess <[EMAIL PROTECTED]> wrote:
The $.val() function returns an empty value for a <select> element in IE
if a value attribute is not specifically defined in each option. In
Firefox the value (if not found as an attribute of an option) is
extracted from the innerHTML/text of the element. Why this doesn't
happen in IE is beyond me?
Here's the code;
---
<script type="text/javascript">
$().ready(function() {
alert($('select').val());
$('select').change(function() { alert($(this).val()); });
});
</script>
<select>
<option>a</option>
<option SELECTED>b</option>
<option>c</option>
</select>
---
FF will alert "b" on load, and on changing the select, will alert
"a","b", or "c" depending on what has been selected.
IE alerts "" on load, and continues to do so on change.
NOW --> If I change the <select> to read;
<select>
<option value="a"/>
<option SELECTED value="b"/>
<option value="c"/>
</select>
It works (alerts correctly), but the <select> does not display the
values in the drop down menu -- so I must use
<select>
<option value="a">a</option>
<option SELECTED value="b">b</option>
<option value="c">c</option>
</select>
Which seems awfully redundant.. but is perhaps the W3C standard? Is this
the only way to go? I still think it is strange that $.val() returns the
value in FF but not in IE...
Thanks!
~ Brice
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/
--
Aaron Heimlich
Web Developer
[EMAIL PROTECTED]
http://aheimlich.freepgs.com
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/