DHTMLX Docs & Samples Explorer

Items Text Manipulation

Select Item New Text
Source
<script src="../../codebase/dhtmlxcommon.js"></script>
<script src="../../codebase/dhtmlxaccordion.js"></script>
<link rel="stylesheet" type="text/css" href="../../codebase/skins/dhtmlxaccordion_dhx_skyblue.css">
<script src="../../codebase/dhtmlxcontainer.js"></script>
 
<div id="accordObj" style="position: relative; width: 320px; height: 400px;"></div>
<div style="margin: 50px 0px 20px 0px;">
Select Item <select id="sel"></select> New Text <input id="newText" type="text" value="New Text"> <input type="button" value="Set Text" onclick="setText();"> <input type="button" value="Get Text" onclick="getText();">
</div>
<script>
var sel = document.getElementById("sel");
var dhxAccord;
function doOnLoad() {
    dhxAccord = new dhtmlXAccordion("accordObj");
    dhxAccord.addItem("a1", "a");
    dhxAccord.addItem("a2", "b");
    dhxAccord.addItem("a3", "c");
    dhxAccord.openItem("a1");
    dhxAccord.forEachItem(function(item) {
        sel.options.add(new Option(item.getText(), item.getId()));
    });
}
function getId() {
    var id = sel.options[sel.selectedIndex].value;
    return id;
}
function setText() {
    dhxAccord.cells(getId()).setText(document.getElementById("newText").value);
}
function getText() {
    alert(dhxAccord.cells(getId()).getText());
}
</script>