Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dojo/form/select onchange event not working for me in dojo 1.8

Tags:

dojo

I am trying out dojotoolkit 1.8 and cant figure out how to hook up an onchange event for a dojo/form/select

Nothing happens with this

require(["dojo/dom","dojo/on"], function(dom,on){
   on(dom.byId("myselect"),"change",function (evt){
         alert("myselect_event");

});

If instead, the following hook into click works:

on(dom.byId("myselect"),"click",function (evt){
  • but i want to capture the value after user clicks and changes

I am sure it is simpler than going back to Plain ol javascript onChange...

Thx

like image 420
Aveesh Avatar asked Nov 26 '12 02:11

Aveesh


2 Answers

You could try something like this:

    var select = dijit.byId('myselect');

    select.on('change', function(evt) {
        alert('myselect_event');
    });

I've seen this in the reference-guide multiple times, eg in the dijit/form/select' s reference-guide at 'A Select Fed By A Store'.

Maybe it even returnes the handle, i haven't looked this up so far. But i guess it should work.

EDIT:

Considering @phusick's comment, i want to add, that you could also simply change the "change" to "onChange" or the dom to dijit within calling on(...)

like image 54
nozzleman Avatar answered Sep 22 '22 15:09

nozzleman


Following in the footsteps of @nozzleman's answer try

var select = registry.byId('myselect');

select.on('change', function(evt) {
    alert('myselect_event');
});

If you use on instead of connect then you don't have to write onChange, you can simply write change.

like image 41
Gaurav Ramanan Avatar answered Sep 24 '22 15:09

Gaurav Ramanan