Reputation: 3
Hi friends I am new to "DOJO". I tried to create a button and onclick event I want it to call a function, my code as follows
<input id="execute" type="button" value="Get Details">
require([
"dojo/dom","dojo/on","dojo/domReady!"
], function(
dom,on
) {
on(dom.byId("execute"), "click", execute);
function execute () { alert("here");}
});
But the function execute is not calling. I tried a lot, but not working. Please help me guys.
Upvotes: 0
Views: 1032
Reputation: 44685
The code itself works fine as you can see in this fiddle: http://jsfiddle.net/f7bwK/
But I'm noticing that you're not putting <script>
tags around your code, is that just because you copy pasted it here, or did you really forget them? Your code should (at least) be something like:
<input id="execute" type="button" value="Get Details">
<script type="text/javascript">
require([
"dojo/dom","dojo/on","dojo/domReady!"
], function(
dom,on
) {
function execute () { alert("here");}
on(dom.byId("execute"), "click", execute);
});
</script>
If you just didn't copy these, then verify if Dojo is loaded or not. Also, try and see if moving the execute()
function above the on()
function solves the problem.
If these solutions do not solve your problem, open your browser console (usually F12 or Ctrl+Shift+I) and see if any error occurs.
Upvotes: 1