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


Reply via email to