Results 1 to 5 of 5

Thread: Is selectedindex standard?

  1. #1
    Join Date
    Apr 2008
    Location
    San Diego, CA
    Posts
    352
    Thanks
    57
    Thanked 6 Times in 6 Posts

    Default Is selectedindex standard?

    Hi all,

    Not having a lot of luck with Google:

    http://www.google.com/search?hl=en&q...rg&btnG=Search

    My best guess from these results is that selectedIndex is standard in HTML5?

    Do I need to be careful when using selectedIndex? Is it standard, or just quasi-de facto standard like innerHTML?

    Thanks guys.
    Last edited by jlizarraga; 12-02-2008 at 12:10 AM. Reason: clarification

  2. #2
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    selectedIndex is a standard based on DOM level 1

  3. #3
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Yes it is standard in javascript. It generally has no useful cross browser value without reference to a select element and its option(s) of which one is selected though. Consider:

    Code:
    select_element.options.selectedIndex
    That's (assuming that select_element exists and has at least one option that is selected) a number (0 to whatever).

    Any other use may or may not have any value in any given browser, although a select element with no options (technically invalid), or no option selected will generally have a options.selectedIndex that is out of range (usually -1, or possibly NaN, etc.).

    All of this probably sounds complicated because it is just the general description of its possible usage. If so, and there is something in particular that you wold like to do, give us the details and we can probably help a lot more.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  4. The Following User Says Thank You to jscheuer1 For This Useful Post:

    jlizarraga (12-02-2008)

  5. #4
    Join Date
    Apr 2008
    Location
    San Diego, CA
    Posts
    352
    Thanks
    57
    Thanked 6 Times in 6 Posts

    Default

    Thanks a bunch for your responses. It's working out fine, just wanted to make sure I wouldn't find out later that my app is broken in some lesser used browser.

  6. #5
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I should have also mentioned that the selectedIndex is a setter as well as a getter. That means that it may be used via javascript to set which option is selected.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •