Question

I m trying to set a on click event dynamically to a dijit/form/Button. But, the method I m trying doesn't seem to work.

<button id = "newActButton" data-dojo-type="dijit/form/Button"
    type = "button" 
    data-dojo-props="iconClass: 'newActButtonIcon', label: 'New Act'"></button>


dijit.byId("newActButton").set("onClick", newActButtonOnClick());

I have a function newActButtonOnClick(), which I want to fire.

Was it helpful?

Solution

You may try something like this:

require(["dojo/on", "dojo/dom", "dojo/domReady!"],
    function(on, dom) {
        var newActButton = dom.byId("newActButton");

        on(newActButton, "click", newActButtonOnClick);
});

Here's tutorial

jsfiddle

OTHER TIPS

It doesn't work because you have an error in your code (by.Id VERSUS byId):

dijit.by.Id("newActButton").set("onClick", newActButtonOnClick());

should be

dijit.byId("newActButton").set("onClick", newActButtonOnClick());

EDIT

Try this:

require(["dojo/parser", "dijit/form/Button"]);

<button data-dojo-type="dijit/form/Button" type="button">Click me too!
    <script type="dojo/on" data-dojo-event="click" data-dojo-args="evt">
        require(["dojo/dom"], function(dom){
            dom.byId("result2").innerHTML += "Thank you! ";
        });
    </script>
</button>
<div id="result2"></div>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top