Joseph DeVore's Blog: Select ALL options in a CFSELECT (when using MULITPLE="yes")


Viewing By Entry / Main
October 13, 2005
If you ever have the need to select all of the options in a select box, this code does just that.

<cfform format="flash" name="mulitselect" width="300" height="300">
   <cfformitem type="script">
      var selectAllOptions = function(selectBox:Object):Void {
         var options:Array = Array();
         
         for(var i:Number=0; i <= selectBox.length; i++) {
            options.addItem(i);
         }
         selectBox.selectedIndices=options;   
      }
   </cfformitem>
   <cfselect name="mySelectBox" multiple="yes" size="5" >
      <option value="option 1">1</option>
      <option value="option 2">2</option>
      <option value="option 3">3</option>
      <option value="option 4">4</option>
      <option value="option 5">5</option>
   </cfselect>
   
   <cfinput type="button" name="q" value="SELECT ALL" onclick="selectAllOptions(mySelectBox)">
</cfform>

Comments

Comments are not allowed for this entry.













Editor Login ›