ff extension. how to pass parameters to a function in the oncommand attribute in menu

Posted by encryptor on Stack Overflow See other posts from Stack Overflow or by encryptor
Published on 2010-04-29T10:33:10Z Indexed on 2010/04/29 10:37 UTC
Read the original article Hit count: 381

Filed under:
|
|
|

I have a ff extension which creates a popup and shows dynamic data in it. basically when the popup opens a js function is run which then constructs the popup list by appending the items like this

var myMenuPopup = document.getElementById("file-popup4");

newItem = document.createElement("menuitem");

    newItem.setAttribute("label", namelist[m]);

    newItem.setAttribute("id", "item" + m);

Now I need to have the click functionality too on these newly added menuitems. putting the atttribute and forming the function is easy. I can have a function to be run when they are clicked. But i need to pass namelist[i] to the function and it will act according to the namelist parameter.If i do:

newItem.setAttribute("oncommand" , finalclick(namelist[m]));

it runs the function everytime the popup opens runs the function without even clicking on it

on the other hand if i use quotes i.i if i do

newItem.setAttribute("oncommand" , "finalclick(namelist[m])");

it doesnot open even on clicking giving error : namelist is not defined.

© Stack Overflow or respective owner

Related posts about firefox

Related posts about xul