3
votes

I have a firefox extension Options pref panel, where I should dynamically create menu items and select particular item to be current.

here is the XUL file part

<menulist id="rss_service_combo">
    <menupopup id="rss_service_menu"/>
</menulist>

Then in load event of the pref panel, using js I append menuitem elements into menupop. This is working fine. The only problem is that even if I set the selected element the item is not selected and combo box is initially empty.

The only way is working at the moment is if I manually add those menuitems into XUL file and set selected attribute, but I need to do it dynamically.

1

1 Answers

0
votes

You are probably looking for the selectedIndex attribute. Here's some sample code for adding menu items dynamically:

// In a for loop...
var menuItem = document.createElement("menuitem");
menuItem.setAttribute("oncommand", "alert('Hi!');");
menuItem.setAttribute("label", basename);
aMenu.appendChild(menuItem);