Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by krzak on Dec 03, 2007 13:23
open dhtmlx forum
dhtmlxtree_start.js and events

I can't make working tree with <xmp/> section to use events. I made event attach but it's never called;

<script>
    function tonopen(id,mode){
        alert("QQ");
        return true;
    };

    function onLoad()
    {
        tree = new dhtmlXTreeObject(document.getElementById('treeframe'),"100%","100%",0);
        tree.setOnOpenHandler(tonopen);
    }
</script>
<body onLoad="onLoad();">

<div id="treeframe" setImagePath="/script/codebase/imgs/" class="dhtmlxTree" style="width:200px">
    <xmp container="true">
    <item text="test" open="1" id="1">
        <item text="trans" select="1" open="1" id="11"/>
        <item text="foo" open="1" id="12"/>
        <item text="end" id="13"/>
    </item>
    </xmp>
</div>
Answer posted on Dec 04, 2007 02:35
You are mixing two different initialization - by script, and by HTML markup
Correct code will look similar to next

init by JS

<script>
    function tonopen(id,mode){
        alert("QQ");
        return true;
    };

    function onLoad()
    {
        tree = dhtmlXTreeFromHTML('treeframe');
        tree.setOnOpenHandler(tonopen);
    }
</script>
<body onLoad="onLoad();">

<div id="treeframe" setImagePath="/script/codebase/imgs/" style="width:200px">        <<class not set , to prevent auto init
    <xmp container="true">
    <item text="test" open="1" id="1">
        <item text="trans" select="1" open="1" id="11"/>
        <item text="foo" open="1" id="12"/>
        <item text="end" id="13"/>
    </item>
    </xmp>
</div>


Init from HTML

<script>
    function tonopen(id,mode){
        alert("QQ");
        return true;
    };

</script>
<body onLoad="onLoad();">

<div setOnOpenHandler="tonopen" id="treeframe" setImagePath="/script/codebase/imgs/" class="dhtmlxTree" style="width:200px">
    <xmp container="true">
    <item text="test" open="1" id="1">
        <item text="trans" select="1" open="1" id="11"/>
        <item text="foo" open="1" id="12"/>
        <item text="end" id="13"/>
    </item>
    </xmp>
</div>