I'm making a card game in Javascript and one of the things the webpage does is create buttons with the name of a card that you click to use the card. At least, in theory.
Code:
function addButton(card) {
var newbutton = document.createElement("input");
newbutton.setAttribute("type", button);
newbutton.setAttribute("id", 'someButton');
newbutton.setAttribute("value",card.displayName);
newbutton.setAttribute("name",card.name);
newbutton.setAttribute("onclick",'useCard(name)'); ///this is what's not working
What I'd like is for the onclick attribute to use the named card (the card's name is card.name, which might be different from its displayed name). Instead, it's using useCard with 'name' as the argument, which is obviously wrong. What's the correct line of code here?
buttonandnameare variables from an outer scope?