Programaticly calling toolbar button click event

So the way I have handled onClick for a toolbar is to attach a single event, but using select/case run specific code for each id that is passed. Is there a way to run the onClick event and pass the button id from another function? I was looking at this: viewtopic.php?f=4&t=25023&p=79435&hilit=callEvent#p79435 , but so far I haven’t been able to modify it so that it works for onClick.

Can you describe more in detail what do you need (step by step)?

Darya,

Basically, I want to call the onClick function of a toolbar from another function.

Made you a demo based on that linked approach.
There are some functions, which calls events.
tlb_onclick.rar (54.4 KB)

Darya,

Thanks, I was able to get that far, but when I add a regular button object with the following code and the onClick event handler to it, how can I call that from another function?

[code]toolbar.addButton(“print”, 1, “Print”, “print.gif”, “print_dis.gif”);

toolbar.attachEvent(“onClick”, function(id){
switch (id){
case “print”:
alert(id + “clicked”)
break;
}
});[/code]

hi

you you need programmaticaly call click button (i.e. emulate user action)

// add once
dhtmlXToolbarObject.prototype.clickButton = function(id,state) {
	if (typeof(state) !== "boolean") state = true;
	if (!state) this.callMyEvent(this.objPull[this.idPrefix+id].obj, "click");
	this.callMyEvent(this.objPull[this.idPrefix+id].obj, state?"mouseover":"mouseup");
	this.callMyEvent(this.objPull[this.idPrefix+id].obj, state?"mousedown":"mouseout");
	var t = this;
	window.setTimeout(function(){t.clickButton(id,false);t=null;},200); // change this to keep button highlighted
};

dhtmlXToolbarObject.prototype.callMyEvent = function(obj, name) {
	if (document.createEvent) {
		var e = document.createEvent("MouseEvents");
		e.initEvent(name, true, false);
		obj.dispatchEvent(e);
	} else if (document.createEventObject) {
		var e = document.createEventObject();
		e.button = 1;
		obj.fireEvent("on"+name, e);
	}
};
// to call click
toolbar.clickButton(id);

if you just need to run click-callback,

toolbar.callEvent("onClick", [id]);

Hi Andrei
I used the emulate user action.
This function runs correctly on my toolbar but I have problems in the toolbar to add a button select and I can’t select an option opens and closes the window this is due to this line of code (window.setTimeout).
I modify and I have error:

dhtmlXToolbarObject.prototype.clickButton = function(id,state) { if (typeof(state) !== "boolean") state = true; if (!state) this.callMyEvent(this.objPull[this.idPrefix+id].obj, "click"); this.callMyEvent(this.objPull[this.idPrefix+id].obj, state?"mouseover":"mouseup"); this.callMyEvent(this.objPull[this.idPrefix+id].obj, state?"mousedown":"mouseout"); var t = this; function ExeClickButton(){ t.clickButton(id,false); t=null; } ExeClickButton(); };

How I can resolve this problem

Regards
Ricardo

This function runs correctly on my toolbar but I have problems in the toolbar to add a button select and I can’t select an option opens and closes the window this is due to this line of code (window.setTimeout).


http://www.leather-power.com