Getting IE6 to auto-select an item in a dropdown [jQuery]

Discussion in 'Javascript' started by Mr. Wilson, Mar 21, 2007.

  1. Mr. Wilson

    Mr. Wilson Guest

    On this page (just a demo) I can’t get IE6 to auto-select the first item
    in the dynamically-generated drop-down menus. Well, that isn’t entirely
    true. Sometimes it works properly, but never on the first try. When it
    fails, the error message it gives is:

    "Cannot set the selected property. Unspecified error."

    FF2, IE7, and OP9 all behave as expected. I have tried a variety of
    workarounds to no avail. I don't have an exhaustive list of everything I
    have tried, but it seems like I have tried a hundred ways of setting the
    "selected" attribute.

    The page uses jQuery 1.1.2. Currently the page is using...

    $("#select-how option:first-child").attr("selected","selected");

    ....to auto-select the first item in the list.

    Can anybody offer me some clues?

    --Mr. Wilson
     
    Mr. Wilson, Mar 21, 2007
    #1
    1. Advertising

  2. Mr. Wilson

    RobG Guest

    On Mar 22, 3:34 am, "Mr. Wilson" <> wrote:
    > On this page (just a demo) I can't get IE6 to auto-select the first item
    > in the dynamically-generated drop-down menus. Well, that isn't entirely
    > true. Sometimes it works properly, but never on the first try. When it
    > fails, the error message it gives is:
    >
    > "Cannot set the selected property. Unspecified error."


    Set the selected and defaultSelected attributes of the first option
    when you create the list. No further action required.

    --
    Rob
     
    RobG, Mar 21, 2007
    #2
    1. Advertising

  3. Mr. Wilson

    -Lost Guest

    "Mr. Wilson" <> wrote in message
    news:etrqat$ddu$...
    > On this page (just a demo) I can’t get IE6 to auto-select the first item in the
    > dynamically-generated drop-down menus. Well, that isn’t entirely true. Sometimes it
    > works properly, but never on the first try. When it fails, the error message it gives
    > is:
    >
    > "Cannot set the selected property. Unspecified error."
    >
    > FF2, IE7, and OP9 all behave as expected. I have tried a variety of workarounds to no
    > avail. I don't have an exhaustive list of everything I have tried, but it seems like I
    > have tried a hundred ways of setting the "selected" attribute.
    >
    > The page uses jQuery 1.1.2. Currently the page is using...
    >
    > $("#select-how option:first-child").attr("selected","selected");
    >
    > ...to auto-select the first item in the list.
    >
    > Can anybody offer me some clues?


    You do realize the default selection in most cases is the first element, therefore the
    first-child?

    I tested last-child, for example, in Internet Explorer 6 using jQuery 1.1.2 with no issue
    or complaint. The last option of my select list was chosen by default.

    -Lost
     
    -Lost, Mar 22, 2007
    #3
  4. Mr. Wilson

    RobG Guest

    On Mar 22, 6:12 pm, "-Lost" <> wrote:
    [...]
    > You do realize the default selection in most cases is the first element,


    In practice, yes. But it is only convention to do so - the HTML
    specification doesn't reqire it. It is good practice (though rarely
    done) to ensure one option has the 'selected' attribute set.

    If no option has its selected attribute set, Safari will not reset it
    when the form's reset method is called either by script or using a
    reset button.


    > therefore the first-child?


    In some browsers, a select's firstChild might be a text node. I'm no
    expert on jQuery, but it seems to skip text nodes when searching for
    decendants - which might be a good thing sometimes but not others.

    Responses here should focus on generic javascript and DOM, not a
    particular implementation or library.


    --
    Rob
     
    RobG, Mar 22, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. linkswanted
    Replies:
    1
    Views:
    949
  2. mwr

    ASP.Menu in IE6, cannot select menu item when...

    mwr, Jun 16, 2006, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    264
  3. Ste
    Replies:
    2
    Views:
    149
  4. Aaron Gray
    Replies:
    20
    Views:
    414
    Lasse Reichstein Nielsen
    Jul 27, 2008
  5. lorlarz
    Replies:
    6
    Views:
    220
    David Mark
    Mar 25, 2010
Loading...

Share This Page