I'm trying to set up an onclick event for a dijit/form/button using dojo/on, but instead of firing when the button is clicked, the function fires when the class PostCreate event gets fired.
my HTML to define the button:
<button data-dojo-type="dijit/form/Button" id="btnLondon"
type="button">
London
</button>
I'm attempting to link up the onclick event when Postcreate for the class is fired, but the function is getting called when postcreate fires, before the button gets clicked. Here is my javascript:
postCreate: function () {
submit = dojo.byId("btnSubmit");
on(submit, "click", lang.hitch(this, this.Submit("London")));//this call is made to the function right away
}
Submit: function(Name){
alert(Name);
},
Any idea why this could be happening? I've got dojo/on loaded in my define statement
Thanks
Pete
this.submit("London") syntax means means call function this.submit right now, with parameter "London". That's why it's being called in postCreate.
Instead, a possible adequate syntax is (widgets have an "on" method, you don't have to use dojo/on):
submit.on("click", lang.hitch(this, this.Submit, "London"));
...
Submit: function(name, evt){
alert(name);
}