DHTMLX Docs & Samples Explorer

Menu Items Position Control

Select Item  
(Click menu item to select)
Current Item Position  
 
New Item Position  

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><div id="item">(Click menu item to select)</div></td>
        </tr>
        <tr>
            <td>Current Item Position</td>
            <td>&nbsp;</td>
            <td><div id="item_pos">&nbsp;</div></td>
        </tr>
        <tr>
            <td>New Item Position</td>
            <td>&nbsp;</td>
            <td><input id="item_new_pos" type="text" value="1" style="width: 30px;"> <input type="button" value="Update" onclick="update();"></td>
        </tr>
    </table>
</div>
 
<br>
<script>
var menu,
mid;
function initMenu() {
    menu = new dhtmlXMenuObject("menuObj");
    menu.setIconsPath("../common/imgs/");
    menu.attachEvent("onClick", menuClick);
    menu.loadXML("../common/dhxmenu.xml?e=" + new Date().getTime());
}
function menuClick(id) {
    document.getElementById("item").innerHTML = id + " (" + menu.getItemText(id) + ")";
    document.getElementById("item_pos").innerHTML = menu.getItemPosition(id);
    mid = id;
}
function update() {
    var pos = Number(document.getElementById("item_new_pos").value);
    if (isNaN(pos)) {
        return;
    }
    menu.setItemPosition(mid, pos);
}
</script>