if ($(this).attr("id") == "somevalue")
$(this).attr("selected", true);
Chandan
Intelligrape Software Pvt. Ltd.
On Thu, Jan 29, 2009 at 6:55 PM, markaduncan74@googlemail.com <markaduncan74@googlemail.com> wrote:
Can you set the .val() on the select object, i've tested this in IE 7
but don't have IE6 to hand
<html>
<head>
<script src="neworders_files/jquery-1.js" type="text/javascript"></
script>
<script type="text/javascript">
$(document).ready(function()
{
$('#rob').click(function()
{
$('#bob').val('3');
});
});
</script>
</head>
<body>
<select id="bob">
<option value="1">one</option>
<option value="2">two</option>
<option value="3">three</option>
<option value="4">four</option>
</select>
<input type="button" id="rob" value="select option 3" />
</body>
</html>
On Jan 29, 6:03 am, KenLG <ken.na...@gmail.com> 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 comments:
Post a Comment