www.webdeveloper.com
Results 1 to 5 of 5

Thread: Select all drop down function?

  1. #1
    Join Date
    Jul 2007
    Posts
    461

    Select all drop down function?

    Hi, is there a way, when one select is clicked, all change to the value of the one that was chosen? (ie: "b" is clicked and all change to b.)

    Code:
    <select>
    <option>a</option>
    <option>b</option>
    <option>c</option>
    </select>
    <br>
    
    <select>
    <option>a</option>
    <option>b</option>
    <option>c</option>
    </select>
    <br>
    
    <select>
    <option>a</option>
    <option>b</option>
    <option>c</option>
    </select>
    Thanks

  2. #2
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,436

    Lightbulb

    Try this...
    Code:
    <html>
    <head>
    <title>Multiple selections</title>
    <script type="text/javascript">
    // For: http://www.webdeveloper.com/forum/newreply.php?do=postreply&t=240209
    
    function pickAll(ndx) {
      var sel = document.getElementsByTagName('select');
      for (var i=0; i<sel.length; i++) {
        sel[i].selectedIndex = ndx; 
      }
    }  
    </script>
    </head>
    <body>
    <select id="SBox0" onclick="pickAll(this.selectedIndex)">
    <option>a</option>
    <option>b</option>
    <option>c</option>
    </select>
    <br>
    
    <select id="SBox1" onclick="pickAll(this.selectedIndex)">
    <option>a</option>
    <option>b</option>
    <option>c</option>
    </select>
    <br>
    
    <select id="SBox2" onclick="pickAll(this.selectedIndex)">
    <option>a</option>
    <option>b</option>
    <option>c</option>
    </select>
    </body>
    </html>

  3. #3
    Join Date
    Jul 2007
    Posts
    461
    Cool, thanks!

  4. #4
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,436
    You're most welcome.
    Happy to help.

    In what sort of context would you need this function.
    It would seem to me that you would need to select an option from only ONE select box.

  5. #5
    Join Date
    Jul 2007
    Posts
    461
    Yes it seems convoluted but I ended up making them all hidden inputs just the same; I needed to gather info that applies to multiple objects on one page basically.

    Thanks again!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles