DHTMLX Docs & Samples Explorer

Menu Items State Manipulation

Select Item    

Source
<link rel="stylesheet" type="text/css" href="../../codebase/skins/dhtmlxmenu_dhx_skyblue.css">
<script src="../../codebase/dhtmlxcommon.js"></script>
<script src="../../codebase/dhtmlxmenu.js"></script>
<script src="../../codebase/ext/dhtmlxmenu_ext.js"></script>
 
<div style="height: 250px;"><div id="menuObj"></div></div>
<div>
    <table border="0" cellspacing="0" cellpadding="0">
        <tr>
            <td>Select Item</td>
            <td width="10">&nbsp;</td>
            <td><select id="sel"></select></td>
            <td width="10">&nbsp;</td>
            <td><input type="button" value="Enable" onclick="enable();"> <input type="button" value="Disable" onclick="disable();"> <input type="button" value="Is Enabled?" onclick="isEnabled();"></td>
        </tr>
    </table>
</div>
 
<br>
<script>
var menu;
function initMenu() {
    menu = new dhtmlXMenuObject("menuObj");
    menu.setIconsPath("../common/imgs/");
    menu.loadXML("../common/dhxmenu.xml?e=" + new Date().getTime(), function() {
        var sel = document.getElementById("sel");
        menu.forEachItem(function(id) {
            if (menu.getItemType(id) != "separator") {
                sel.options.add(new Option(menu.getItemText(id), id));
            }
        });
    });
}
function getId() {
    var sel = document.getElementById("sel");
    var id = sel.options[sel.selectedIndex].value;
    return id;
}
function enable() {
    menu.setItemEnabled(getId());
}
function disable() {
    menu.setItemDisabled(getId());
}
function isEnabled() {
    alert(menu.isItemEnabled(getId()));
}
</script>