Hi,
I’m dynamically populating a menu with menuitems and I’m looking to add an even listener to each menu item as it generated.
By doing this, each menu item when clicked, will be added to a textbox.
I know my code for adding to the textbox works, but I can’t seem to get the generated items to work, I think its something to do with me trying to access a ‘menuitem’ which are only generated when the user takes a certain action. Does anyone know how to access generated menuitems?
Generating the menu items
[code]
var menu = document.getElementById(“tagmenu”);
for (var j = 0; j < x.length; j++)
{
t = x[j].getAttribute(“content”);
var temp = document.createElement(“menuitem”); // create a new XUL menuitem
temp.setAttribute(“label”, t);
temp.setAttribute(“type”, “checkbox”);
menu.appendChild(temp);
temp.addEventListener(“command”, addTags, false);
}
Adding generated items to textbox
[code]
function addTags()
{
var x= document.getElementById(“menuitem”);
y = x.getAttribute(“label”);
if (x.checked = true)
{
var t = document.getElementById(“get-tag”);
t.setAttribute(“value”, y);
}
}