Extra data with templates
Select option to view extra data
</> Source
<!DOCTYPE html>
<html>
<head>
<title>Extra data with templates</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>
<style>
div.combo_info {
color: gray;
font-size: 11px;
padding-bottom: 5px;
padding-left: 2px;
font-family: Tahoma;
}
#log_here {
font-size: 8pt;
font-family: Tahoma;
width: 500px;
height: 120px;
border: 1px solid #cecece;
padding: 2px 5px;
overflow: auto;
}
</style>
<script>
var myCombo;
var eventIndex = 1;
function doOnLoad() {
myCombo = new dhtmlXCombo("combo_zone", null, null, "image");
myCombo.setImagePath("../common/flags/");
myCombo.enableFilteringMode(true);
myCombo.setTemplate({
input: "#capital#", // what you will see in input
option: "#capital# - #country#" // what you will see in option text
});
myCombo.addOption("1", {country: "Finland", capital: "Helsinki", flag: "finland.png"}, null, "finland.png", true);
myCombo.addOption("2", {country: "Germany", capital: "Berlin", flag: "germany.png"}, null, "germany.png");
myCombo.addOption("3", {country: "Great Britain", capital: "London", flag: "britain.png"}, null, "britain.png");
myCombo.addOption("4", {country: "Hungary", capital: "Budapest", flag: "hungary.png"}, null, "hungary.png");
myCombo.attachEvent("onChange", function(value, text){
var option = myCombo.getOption(value);
// option.text will gives you {country: "Finland", capital: "Helsinki", flag: "finland.png"} for value=>"1"
log(option.text.country+", "+option.text.capital+" <span style='vertical-align:baseline;'><img border='0' src='../common/flags/"+option.text.flag+"' style='vertical-align:middle;'></span>");
});
}
function log(text) {
var t = document.getElementById("log_here");
t.innerHTML += (eventIndex++)+") "+text+"<br>";
t.scrollTop = t.scrollHeight;
}
</script>
</head>
<body onload="doOnLoad();">
<h3>Select option to view extra data</h3>
<div id="combo_zone" style="width:230px;"></div>
<br><br><br><br><br><br><br><br><br><br>
<div id="log_here"></div>
</body>
</html>
Documentation
Check documentation to learn how to use the components and easily implement them in your applications.