title: Dojo Toolkit 1.8.3 Mobile dojo/on Handler Event Switch Widget
body: <p>I am trying to create a basic event handler for a dojox.mobile.Switch widget using the onStateChanged event. I am using dojo/on event handler module with respect to the new AMD architecture and having a hard time to get it to listen to my switch event.</p>
  
  <p><strong>Here is the HTML for the switch widget with id=mobileView</strong></p>
  
  <pre><code>    &lt;li data-dojo-type="dojox.mobile.ListItem" data-dojo-props="icon:'../../app/images/i-      icon-1.png'"&gt;
        Mobile Version
      &lt;div id="mobileView" class="mblItemSwitch" data-dojo-type="dojox.mobile.Switch"&gt;&lt;/div&gt;
      &lt;/li&gt;
  </code></pre>
  
  <p><strong>Here is the JS code code. The second require is suppose to handle the switch event.</strong></p>
  
  <pre><code>    require(["dojox/mobile/parser", "dojox/mobile", "dojox/mobile/deviceTheme","dojox/mobile/compat", "dojo/domReady!"],
      function(parser) {
      parser.parse();
      });
  
      require(["dojo/on", "dijit/dijit"], 
      function(on){
      on(dijit.byId("mobileView"), 
      "onStateChanged", 
      function(newState){
      alert(newState);
      });
      });
      &lt;/script&gt;
  </code></pre>
  
  <p>I can see that it is binding itself to the widget using dijit.byId, listening for the event onStateChanged, and calling the preceding function once the state changes. I am thinking it has something to do with having the correct modules included in the require, however I am not really sure. I have spent hours on this and have tried many different methods including the old way of dojo.connect.</p>
  
  <p>Any help/tips would be greatly appreciated!</p>
  
  <p><a href="http://livedocs.dojotoolkit.org/dojo/on" rel="nofollow">Reference: dojo/on Dojo Toolkit dojo/on</a></p>