I’m trying to programmatically insert a dijit.form.Button into some HTML and my code goes like this:
row.innerHTML = '<td>Name:</td><td id="showname" />';
var showButton = new dijit.form.Button({
label: "Show name",
style: "float: right",
onClick: show_name(),
}, "showname")
But every time I refresh and update the page, it will automatically run show_name(), which is not what I want. Can anyone give me some insight as to why this is happening, and how I can fix it so that show_name() is only run when the button is clicked?
Thanks.
Try just
show_name, orfunction() { show_name(); }.My explanation is that you need a function reference, not a function call, which passes back the return value (probably nothing) back to
onClick. The first option works when no arguments are passed, in the second option you can pass anything intoshow_name().