/    Sign up×
Community /Pin to ProfileBookmark

Populating Menus

Hi,

I’ve a function that dynamically populates a menu when a button is clicked, (the menu is populated with checkbox items) this works fine, but I then want to use these checkbox items as input controls, how can I add this functionality to the items as they are only generated when the user clicks a button?

Thanks

This is the code that populates the menu

[code]
var menu = document.getElementById(“tagmenu”);

for (var j = 0; j < x.length; j++)
{

t = x[j].getAttribute(“content”);
const XUL_NS = “http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul”;
var temp = document.createElementNS(XUL_NS, “menuitem”); // create a new XUL menuitem

temp.setAttribute(“label”, t);
temp.setAttribute(“type”, “checkbox”);
menu.appendChild(temp);

}
[/code]

And the code that uses the takes the items from the menu to the output area (a textbox, but currently this just works for already defined menu items).

[code]
var x= document.getElementById(“menuitem”);
y = x.getAttribute(“label”);
if (x.checked = true)
{
var t = document.getElementById(“get-tag”);
t.setAttribute(“value”, y);

}
[/code]

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @Hysteria86 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...