DHTMLX Docs & Samples Explorer

Adding Options

Options can be added in the next ways:

1. By addOption command:

var z=new dhtmlXCombo("combo_zone3","alfa3",200);
  • value - the option value
  • label - the option label
  • css - the css string attached to the option, optional
  • img_src - the path to the option icon image. Available just for the image combo type.

It is possible to add few options at once:

  • as an array of array (in this case you can't use 4th parameter img_src)

    var z=new dhtmlXCombo("combo_zone3","alfa3",200);
               ["a","option A"],
               ["b","option B", "color:red;"],
               ["c","option C"]
  • as an array of objects (you can use 4 parameters)

    var z=new dhtmlXCombo("combo_zone3","alfa3",200);
               {value: "a", text: "option A", img_src: "../images/blue.gif", css:"color:red;"}, 
               {value: "b", text: "option B", img_src: "../images/green.gif"}, 
               {value: "c", text: "option C", img_src: "../images/red.gif"}

2. From XML file:

  var z=new dhtmlXCombo("combo_zone3","alfa3",200);

Where XML has the following format:

  <?xml version="1.0" ?>
     <option value="1">one</option>
     <option value="2">two</option>
     <option value="3">three</option>
     <option value="4">four</option>
     <option value="5">five</option>
     <option value="6">six</option>
     <option value="7">seven</option>
     <option value="8">eight</option>
     <option value="9">nine</option>
     <option value="10">ten</option>

Possible attributes of <option> tag are as follows:

  • value - option value
  • selected - if option is selected
  • img_src - icon url (also add the 4th parameter to combobox constructor - “image”)
  • checked - checkbox state (for combo with “checkbox” type, 0 by default)

3. From autocomplete xml file

Plese check "filtration" section for more details

4. From HTML in case of converting from existing select box