How to get value(s) from Multiple Selection enabled Select Box

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Raghuram Banda

    #1

    How to get value(s) from Multiple Selection enabled Select Box

    Hi All,

    I'm on a task some thing like getting selected value(s) from source
    SELECT box and appending these value(s) to destination SELECT box. Can
    anyone help me how to get multiple values from SELECT box using
    JavaScript (DOM).

    Thanks in advance.

  • Lasse Reichstein Nielsen

    #2
    Re: How to get value(s) from Multiple Selection enabled Select Box

    Raghuram Banda <raghuram.banda @nokia.sify.net > writes:
    [color=blue]
    > I'm on a task some thing like getting selected value(s) from source
    > SELECT box and appending these value(s) to destination SELECT box. Can
    > anyone help me how to get multiple values from SELECT box using
    > JavaScript (DOM).[/color]

    If the select element is "selRef", we can iterate through the selected
    options as:

    for (var i=selRef.option s.length-1; i >= 0;i++) {
    if (selRef.options[i].checked) {
    // do something
    }
    }

    I count backwards, so if you remove the option you are looking at,
    it will not affect the ones you haven't visited yet.

    /L
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    • Lasse Reichstein Nielsen

      #3
      Re: How to get value(s) from Multiple Selection enabled Select Box

      Lasse Reichstein Nielsen <lrn@hotpop.com > writes:
      [color=blue]
      > for (var i=selRef.option s.length-1; i >= 0;i++) {[/color]
      Doh, that should ofcourse be i--
      [color=blue]
      > if (selRef.options[i].checked) {[/color]

      And this should be
      if (selRef.options[i].selected) {


      I hate it when I reflexively press submit before testing.
      /L
      --
      Lasse Reichstein Nielsen - lrn@hotpop.com
      Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
      'Faith without judgement merely degrades the spirit divine.'

      Comment

      Working...