Script - array of objects
Array of objects
Array of objects with image
Array of objects with checkbox
"Array of objects" is recommended way for adding options from script
</> Source
<!DOCTYPE html>
<html>
<head>
<title>Script - array of objects</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<link rel="stylesheet" type="text/css" href="../../../codebase/fonts/font_roboto/roboto.css"/>
<link rel="stylesheet" type="text/css" href="../../../codebase/dhtmlx.css"/>
<script src="../../../codebase/dhtmlx.js"></script>
<script>
var myCombo, myCombo2, myCombo3;
function doOnLoad() {
// Array of objects
myCombo = new dhtmlXCombo("combo_zone");
myCombo.addOption([
{value: "1", text: "Walking through the city", css: "color:red;", selected: true},
{value: "2", text: "Looking oh so pretty", css: "color:green;"},
{value: "3", text: "I've just got to find my way", css: "color:blue;"},
{value: "4", text: "See the ladies flashing", css: "color:magenta;"},
{value: "5", text: "All their legs and lashes", css: "color:darkorange;"},
{value: "6", text: "I've just got to find my way", css: "color:brown;"}
]);
// Array of objects with image
// "img" or "img_src" attr-name for image allowed, "img_dis" or "img_src_dis" allowed also
myCombo2 = new dhtmlXCombo("combo_zone2", null, null, "image");
myCombo2.setImagePath("../common/flags/");
myCombo2.addOption([
{value: "1", text: "Finland", img: "finland.png", selected: true},
{value: "2", text: "Germany", img: "germany.png"},
{value: "3", text: "Great Britain", img_src: "britain.png"},
{value: "4", text: "Hungary", img_src: "hungary.png"}
]);
// Array of objects with checkbox
myCombo3 = new dhtmlXCombo("combo_zone3", null, null, "checkbox");
myCombo3.addOption([
{value: "1", text: "The Adventures of Tom Sawyer"},
{value: "2", text: "The Dead Zone", selected: true},
{value: "3", text: "The First Men in the Moon", checked: true},
{value: "4", text: "The Girl Who Loved Tom Gordon"},
{value: "5", text: "The Green Mile"},
{value: "6", text: "The Invisible Man", checked: true},
{value: "7", text: "The Island of Doctor Moreau", checked: true},
{value: "8", text: "The Prince and the Pauper"}
]);
}
</script>
</head>
<body onload="doOnLoad();">
<h3>Array of objects</h3>
<div id="combo_zone" style="width:230px;"></div>
<br>
<h3>Array of objects with image</h3>
<div id="combo_zone2" style="width:230px;"></div>
<br>
<h3>Array of objects with checkbox</h3>
<div id="combo_zone3" style="width:230px;"></div>
<br><br>
"Array of objects" is recommended way for adding options from script
</body>
</html>
Documentation
Check documentation to learn how to use the components and easily implement them in your applications.