DHTMLX Docs & Samples Explorer

Text Item Label

Source
<script type="text/javascript" src="../../codebase/dhtmlxcommon.js"></script>
<script type="text/javascript" src="../../codebase/dhtmlxtoolbar.js"></script>
<link rel="stylesheet" type="text/css" href="../../codebase/skins/dhtmlxtoolbar_dhx_skyblue.css"></link>
 
<div id="toolbarObj"></div>
<div style="margin-top: 20px;">
<select id="sel"><option value="text">dhtmlxToolbar Demo</option></select>
<input type="button" value="Get Text" onclick="getText();">
<input type="button" value="Set Text" onclick="setText();">
<input id="txt" type="text" value="New Text">
</div>
<script>
var sel = document.getElementById("sel");
var toolbar = new dhtmlXToolbarObject("toolbarObj");
toolbar.setIconsPath("../common/imgs/");
toolbar.loadXML("../common/dhxtoolbar_text.xml?etc=" + new Date().getTime(), updateList);
function setText(text) {
    toolbar.setItemText(sel.options[sel.selectedIndex].value, document.getElementById("txt").value);
    updateList();
}
function getText() {
    var text = toolbar.getItemText(sel.options[sel.selectedIndex].value);
    if (text == "")
        text = "This item hasn't text";
    alert(toolbar.getItemText(sel.options[sel.selectedIndex].value));
}
function updateList() {
    sel.options.length = 0;
    toolbar.forEachItem(function(itemId) {
        if (toolbar.getType(itemId) == "text") {
            sel.options.add(new Option(toolbar.getItemText(itemId), itemId));
        }
    });
}
</script>