DHTMLX Docs & Samples Explorer

Button Select Listed Option Iterator

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: 200px;">
<select id="sel2"></select>
<input type="button" value="Update Text" onclick="updateText();">
<input id="txt" type="text" value="New Text">
</div>
<script>
var sel2 = document.getElementById("sel2");
var toolbar = new dhtmlXToolbarObject("toolbarObj");
toolbar.setIconsPath("../common/imgs/");
toolbar.loadXML("../common/dhxtoolbar_buttonselect.xml?etc=" + new Date().getTime(), updateList);
function getId() {
    var id = sel2.options[sel2.selectedIndex].value;
    return id;
}
function updateText(text) {
    var id = getId();
    var txt = document.getElementById("txt").value;
    toolbar.forEachListOption(id, function(listId) {
        toolbar.setListOptionText(id, listId, txt);
    });
}
function updateList() {
    sel2.options.length = 0;
    toolbar.forEachItem(function(itemId) {
        if (toolbar.getType(itemId) == "buttonSelect") {
            sel2.options.add(new Option(itemId, itemId));
        }
    });
}
</script>