[Project_owners] changing the oncommand attr/prop of <command/>

Bo Yang techrazy.yang at gmail.com
Mon Sep 10 20:13:11 PDT 2007


Eric H. :
> Hi,
>
> I have:
>
> <command id="aId"
>   tooltip="&opts.102.tooltiptext;"
>   oncommand=""
>   observes="account-folder-selected"/>
>
> How can I programmatically change the function that gets called when 
> the command fires? I've tried variations like:
>
> function fcn() { alert('hello wurld'); }
> document.getElementById("aId").setAttribute("oncommand", fcn);
> document.getElementById("aId").setAttribute("oncommand", "fcn");
> document.getElementById("aId").setAttribute("oncommand", fcn());
> document.getElementById("aId").setAttribute("oncommand", "fcn()");
I think this one is OK.
> document.getElementById("aId").oncommand=fcn;
> document.getElementById("aId").oncommand="fcn";
> document.getElementById("aId").oncommand=fcn();
> document.getElementById("aId").oncommand="fcn()";
>
> Should I be using an event listener instead?
Yeah, creating an event listener is a good way to do this.

Regards!
Bo


More information about the Project_owners mailing list