Re the "I'm not even sure that would work" (adding an actual ID attribute to the option)

Curiosity got the better of me and it works in IE7, FF3, Safari 3, Opera 9 & Google Chrome

Didn't check if it's standards-compliant, though.......just never saw it done before.

So KenLG, you have 2 options:

1) Add an actual ID to the option, so that your request for "the option with id='somevalue'" will work
2) Replace the jQuery check with "the option with value='somevalue'"

L

Liam Byrne wrote:
Why have you used ?

if ($(this).attr(*"id"*) == "somevalue")

For that to work, your select box would need to be
<select id="MySelectID">
<option value="">Select something</option>
<option id="somevalue" value="somevalue">My selection</option>
</select>
....and I'm not even sure that would work.

Try

if ($(this).attr("value") == "somevalue")
Liam


KenLG wrote:
I only found a couple posts related to this and none seemed to have
been answered.

If you try to select an <option> using this:

$("#MySelectID option").each( function() {

        if ($(this).attr("id") == "somevalue")
              $(this).attr("selected", "selected");

});//end each

or like this:

$("#MySelectID option[value=somevalue]").attr("selected", "selected");

where the HTML might look like this:

<select id="MySelectID">
<option value="">Select something</option>
<option value="somevalue">My selection</option>
</select>

You get "Could not set the selected property. Unspecified error." from
IE6. No other browsers I know of (IE7, FF2, FF3, etc.) have this
issue.

This was a problem under 1.2.6 and is still a problem under 1.3.1.

Anyone have a solution?

My work around is to just switch back to classic JS and do this:

var oMenu = document.forms[0].elements["MySelectID"];

for(var i=0; i < oMenu.options.length; i++)
{
       if (oMenu.options[i].value == "somevalue")
       {
              oMenu.options[i].selected = true; // or
oMenu.selectedIndex = i
              break;
       }//end if
}//end for

Which, well, sucks. Anyone have a jquery-based workaround that fits it
all into one line or anyone know if there's a fix planned? I mean,
this is Microsoft we're talking about. IE6 isn't going away for
another 18 months and 25% of internet users still use the piece of
crap.

Mozilla can ditch FF2 all they want but they don't have to do what
Microsoft does. Would be nice to have a fix of some kind...

Anyone?
------------------------------------------------------------------------


No virus found in this incoming message.
Checked by AVG - http://www.avg.com Version: 8.0.176 / Virus Database: 270.10.15/1921 - Release Date: 28/01/2009 06:37


------------------------------------------------------------------------


No virus found in this incoming message.
Checked by AVG - http://www.avg.com Version: 8.0.176 / Virus Database: 270.10.15/1923 - Release Date: 29/01/2009 07:13


Reply via email to