Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Alfred Schmidhauser on Jan 19, 2010 08:13
open dhtmlx forum
DHTMLXMenu and calling Javascript function

I initialize the dhtmlxmenu with menu.loadXML(“”); and calling the userdata like that

My xml:
<?xml version='1.0' encoding='iso-8859-1'?>
<menu id="0">
<item id="about" text="About us">
<item id="comp" text="Company"><userdata name="url">slides/slide1.html</userdata></item>
<item id="comp" text="Company"><userdata name="url">how to calling function writeToDoc???</userdata></item>
</menu>

Menu init:
var menu;
function initMenu() {
 menu = new dhtmlXMenuObject("menuObj");
 menu.setIconsPath("codebase/imgs/csh_bluebooks/");
 menu.attachEvent("onClick", menuClick);  
 menu.loadXML("common/myMenu.xml?etc=" + new Date().getTime());
}

Menu onClick
function menuClick(id) {
ud = menu.getUserData(id, 'url');
 document.getElementById('ifrm').src=ud;
}

Now I need to know how to calling javascript form xml tag which it looks like that:

function  writeToDoc() {
 document.getElementById("status").innerHTML = “Some trxt”;
}

Thank you in advance

Answer posted by Alex (support) on Jan 19, 2010 08:49

possibly the following can be used:

<?xml version='1.0' encoding='iso-8859-1'?>
<menu id="0">
<item id="about" text="About us">
<item id="comp" text="Company"><userdata name="url">slides/slide1.html</userdata></item>
<item id="comp1" text="Company1"><userdata name="function">writeToDoc()</userdata></item>
</menu>

function menuClick(id) {
ud = menu.getUserData(id, 'url');

if(ud) document.getElementById('ifrm').src=ud;

func = menu.getUserData(id, 'function');

if(func) eval(func);
}

Answer posted by Alfred Schmidhauser on Jan 21, 2010 10:15

Alex, It works perfect!

Thanks a lot for your kind support!

Alfred