select options property

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Christopher Benson-Manica

    #1

    select options property

    I understand that the options property of a select element is an array
    of the options displayed by the select element. If that's so, then
    why can't I sort the array? Rather, I *want* to sort the options =
    how do I do it?

    --
    Christopher Benson-Manica | I *should* know what I'm talking about - if I
    ataru(at)cybers pace.org | don't, I need to know. Flames welcome.
  • Reply Via Newsgroup

    #2
    Re: select options property

    Christopher Benson-Manica wrote:
    [color=blue]
    > I understand that the options property of a select element is an array
    > of the options displayed by the select element. If that's so, then
    > why can't I sort the array? Rather, I *want* to sort the options =
    > how do I do it?
    >[/color]

    I've not sorted anything in js yet but... I'm wondering if you are
    sorting by the option value as opposed to the text value... Can you
    provide some code, or a url for someone here to look at?

    randelld

    Comment

    • Matt Kruse

      #3
      Re: select options property

      "Christophe r Benson-Manica" <ataru@nospam.c yberspace.org> wrote:[color=blue]
      > I understand that the options property of a select element is an array
      > of the options displayed by the select element. If that's so, then
      > why can't I sort the array? Rather, I *want* to sort the options =
      > how do I do it?[/color]

      I have selectbox functions available, and one of them is a sortSelect()
      method. It might do what you want, or get you started in the right
      direction:


      --
      Matt Kruse
      Javascript Toolbox: http://www.mattkruse.com/javascript/


      Comment

      • Christopher Benson-Manica

        #4
        Re: select options property

        Matt Kruse <newsgroups@mat tkruse.com> spoke thus:
        [color=blue]
        > I have selectbox functions available, and one of them is a sortSelect()
        > method. It might do what you want, or get you started in the right
        > direction:
        > http://www.mattkruse.com/javascript/selectbox/[/color]

        Is it just me, or was there a newline deficiency when you wrote the
        scripts? :) Anyway, from what I can see it looks like you're doing
        the same thing I am, which is to use an array to actually sort the
        data and then repopulate the select element. What I really wanted to
        know is why the options property returns something that can't be
        sorted with sort()...

        --
        Christopher Benson-Manica | I *should* know what I'm talking about - if I
        ataru(at)cybers pace.org | don't, I need to know. Flames welcome.

        Comment

        • Matt Kruse

          #5
          Re: select options property

          "Christophe r Benson-Manica" <ataru@nospam.c yberspace.org> wrote:[color=blue]
          > Is it just me, or was there a newline deficiency when you wrote the
          > scripts? :)[/color]

          Nah, the page is just linked to the 'compact' version of the source. If you
          click on the 'Source' link at the top, you can get it in its full commented
          form to read and understand. The compact version is for 'production' use
          where you might want to reduce file size :)
          [color=blue]
          > What I really wanted to
          > know is why the options property returns something that can't be
          > sorted with sort()...[/color]

          Options are very picky, I've found. In most browsers that I've tested, you
          can't manipulate or move around the option objects. In fact, caching
          Option() objects in scripts and then adding or removing them from lists
          causes odd behavior. Based on my testing with multiple browsers, the best
          way to manipulate options is to always create a new Option() object and
          replace an option or add it to the list. Doing anything else causes very
          unpredictable results.

          --
          Matt Kruse
          Javascript Toolbox: http://www.mattkruse.com/javascript/


          Comment

          • Michael Winter

            #6
            Re: select options property

            On Wed, 14 Apr 2004 20:50:43 +0000 (UTC), Christopher Benson-Manica
            <ataru@nospam.c yberspace.org> wrote:
            [color=blue]
            > I understand that the options property of a select element is an array
            > of the options displayed by the select element. If that's so, then
            > why can't I sort the array? Rather, I *want* to sort the options =
            > how do I do it?[/color]

            HTMLSelectEleme nt.options is not an array, but a collection. Collections
            have length properties and they can be subscripted like arrays, but they
            do not have the methods and other properties that arrays do.

            Mike

            --
            Michael Winter
            M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

            Comment

            • Christopher Benson-Manica

              #7
              Re: select options property

              Michael Winter <M.Winter@bluey onder.co.invali d> spoke thus:
              [color=blue]
              > HTMLSelectEleme nt.options is not an array, but a collection. Collections
              > have length properties and they can be subscripted like arrays, but they
              > do not have the methods and other properties that arrays do.[/color]

              Ah, thank you - that's what I was looking for.

              --
              Christopher Benson-Manica | I *should* know what I'm talking about - if I
              ataru(at)cybers pace.org | don't, I need to know. Flames welcome.

              Comment

              Working...