0

while clicking on the button on.click event is not fired and getting error "Cannot read property 'on' of undefined",how to solve this issue.

Simple Map html, body, #map { height: 100%; width: 100%; margin: 0; padding: 0; } body { background-color: #FFF; overflow: hidden; font-family: "Trebuchet MS"; } var map,navToolbar;

  require(["esri/map",
           "dojo/dom",
           "dojo/on",
           "dijit/form/Button",
           "dojo/domReady!"], function(Map,dom,on,parser,registry) {
      map = new Map("map", {
      basemap: "streets",  
      center: [72, 25.75], 
      zoom: 5
    });
    //navToolbar = new Navigation(map);
      //on(navToolbar, "onExtentHistoryChange", extentHistoryChangeHandler);

    dijit.registry.byId("clickMe").on("click",showMessage);
    function showMessage(){
     alert("Hello")
    }       
});

</script>

Click Me

  • Could be a couple of things. Can you show what the html for the button element looks like? It should of course have id="clickMe" as one of its attributes and will need to be of data-dojo-type="dijit/form/Button" – jbchurchill Dec 4 '15 at 13:49
2

you are missing several modules in your require() call, so the mapping of the aliases in your callback are incorrect.

require([
  "esri/map",
  "dojo/dom",
  "dojo/on",
  "dojo/parser", // < this one
  "dijit/registry", // < and this one
  "dijit/form/Button",
  "dojo/domReady!"], function(Map, dom, on, parser, registry, Button) {

afterwards, you need to use your alias when you call on and ensure the corresponding <div> is present.

registry.byId("clickMe").on("click",showMessage);
// ...
<div id="clickMe"></div>

see this old blog of mine for more information.

related threads

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.