DHTMLX Docs & Samples Explorer

Two-State Button State

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"></select>
<input type="button" value="Enable" onclick="enable();">
<input type="button" value="Disable" onclick="disable();">
<input type="button" value="Is Enabled" onclick="isEnabled();">
</div>
<script>
var sel = document.getElementById("sel");
var toolbar = new dhtmlXToolbarObject("toolbarObj");
toolbar.setIconsPath("../common/imgs/");
toolbar.loadXML("../common/dhxtoolbar_button2state.xml?etc=" + new Date().getTime(), updateList);
function getId() {
    var id = sel.options[sel.selectedIndex].value;
    return id;
}
function enable() {
    var id = getId();
    toolbar.enableItem(id);
}
function disable() {
    var id = getId();
    toolbar.disableItem(id);
}
function isEnabled() {
    var id = getId();
    alert(toolbar.isEnabled(id));
}
function updateList() {
    sel.options.length = 0;
    toolbar.forEachItem(function(itemId) {
        if (toolbar.getType(itemId) == "buttonTwoState") {
            sel.options.add(new Option(toolbar.getItemText(itemId), itemId));
        }
    });
}
</script>