YUI 3 programmatically fire change event
Posted
by Jasie
on Stack Overflow
See other posts from Stack Overflow
or by Jasie
Published on 2009-07-31T21:35:51Z
Indexed on
2010/05/07
4:08 UTC
Read the original article
Hit count: 482
Hi all,
I was wondering how to programmatically fire a change event with YUI3 -- I added a change listener to one select box node:
Y.get('#mynode').on('change', function(e) {
Alert(“changed me”);
});
and somewhere else in the script want to fire that event. It works, of course, when a user changes the select box value in the browser. But I've tried many ways to fire it programmatically, none of which have worked. Including:
// All below give this error: T[X] is not a function (referring to what's called in .invoke(), // in the minified javascript
Y.get('#mynode').invoke('onchange');
Y.get('#mynode').invoke('change');
Y.get('#mynode').invoke('on','change');
Y.get('#mynode').invoke("on('change')");
/* Tried using .fire() which I found here:
* http://developer.yahoo.com/yui/3/api/EventTarget.html#method_fire
* Nothing happens
*/
Y.get('#mynode').fire('change');
/* Looking around the APIs some more, I found node-event-simulate.js:
* http://developer.yahoo.com/yui/3/api/node-event-simulate.js.html,
* which by its name would seem to have what I want. I tried:
* Error: simulate(): Event 'change' can't be simulated.
* ( (function(){var I={},B=new Date().getTim...if(B.isObject(G)){if(B.isArray(G)){E=1;\n)
*/
Y.get('#mynode').simulate('change');
Any help would be appreciated!
© Stack Overflow or respective owner