views:

88

answers:

1

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.

A: 
newItem.setAttribute("oncommand" , "finalclick(\"" + namelist[m] + "\")");
Amarghosh
hey amar, this doesnt work either. the error console gives an error:name1 is not defined. where name1 is the name that i click on the popup. Also I have given an alert on the finalclick(groupname) function to display the groupname. No alert comes
encryptor
@encryptor I updated the code, try now.
Amarghosh
@amarghosh. something is wrong in the syntax. what did you intend to do actually? i think some quote is extra or missing.anyways it doesnt work!
encryptor
@encryptor What did you get with the updated one - what was the error message? Try this one: `newItem.setAttribute("oncommand" , "finalclick('" + namelist[m] + "')");`
Amarghosh
ok newitem.onclick = function(){finalclick(namelist[m])}this works but now it does not keep track of m. its showing only undefined. this is probably because the construction of the item is done much before its clicked. at the time of click, it looses track of the array and the variable m.can we come out of this somehow?
encryptor
@encryptor If `newItem.setAttribute("label", namelist[m]);` is working as exptected (if the label is set correctly), the line `newItem.setAttribute("oncommand" , "finalclick('" + namelist[m] + "')");` should also work: it effectively creates `newItem.setAttribute("oncommand" , "finalclick('the label')");` - which means `finalclick('the label');` will be called upon clicking the menu item.
Amarghosh