Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Senior Coder
    Join Date
    May 2004
    Posts
    1,464
    Thanks
    15
    Thanked 0 Times in 0 Posts

    unselecting all on multicombo

    I have multiple select box
    where the first option is
    <option selected value="">All</option>

    is there anyway that if anything is selected other then all then it automatically deselects all?

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Code:
    function deselect(sel){
      for (var i=0; i<sel.options.length; i++){
         sel.options[i].selected = false;
      }
    }
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #3
    Senior Coder
    Join Date
    May 2004
    Posts
    1,464
    Thanks
    15
    Thanked 0 Times in 0 Posts
    so what does this do and how do I use it?

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    It deselects all the options of the given select object.
    Code:
    <form>
    <select name="select1">
    <option selected value="">All</option>
    <option selected value="1">item 1</option>
    <option selected value="2">item 2</option>
    <option selected value="3">item 3</option>
    ...
    </select>
    <input type="button" value="Deselect" onclick="deselect(this.form.select1);" />
    </form>
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #5
    Senior Coder
    Join Date
    May 2004
    Posts
    1,464
    Thanks
    15
    Thanked 0 Times in 0 Posts
    but is there anyway for me to automatically if any options are selected then the first option will be unselected?

  • #6
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    I thought you want to deselect all options? Now you want to deselect the first option if anything are selected other than the first option?
    Code:
    function deselect(sel){
      var selected = false;
      for (var i=1; i<sel.options.length; i++){
         if (sel.options[i].selected) {
            selected = true;
            break;
         }
      }
      if (selected) {
         sel.options[0].selected = false;
      }
    }
    Code:
    <form>
    <select name="select1" size="3" multiple="multiple" onchange="deselect(this);">
    <option value="">All</option>
    <option value="1">item 1</option>
    <option value="2">item 2</option>
    <option value="3">item 3</option>
    ...
    </select>
    </form>
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________


  •  

    Posting Permissions

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