0
/* listen for the submit button press */

YAHOO.util.Event.addListener(webserver.result_form, 'submit', webserver.result_submit);

I have this event listener in my main.js. Is there any way in YUI so I can listen a variable, so when this variable changes the event occurs. I was wondering if there is something like :

YAHOO.util."Variable".addListener(webserver.result_form, 'submit', webserver.result_submit);
evotopid
  • 5,288
  • 2
  • 26
  • 41

1 Answers1

1

you can not directly assign listener to javascript variable but you can do it indirectly in following manner.

you can save the value of a variable in a div or any html node

e.g.

<div id="variable-name" style="display:none;">variable-value</div>

or

<span id="variable-name" style="display:none;">variable-value</span>

and then use following js to monitor any change in the node. This will work in YUI3 or above. ( I am not sure about YUI2.x)

var Y = YUI().use('node', 'event', function (Y) {
    // node and event modules are loaded.
});    
var demo = Y.one('#variable-name');
    // And we can listen for DOM events.
        demo.on('change', function (e) {
            alert('value changed');
        });

for more info about listening for events to YUI node

http://yuilibrary.com/yui/docs/event/#listening-for-events

and lists of events available

http://yuilibrary.com/yui/docs/event/#event-whitelist




EDIT


based on http://www.quirksmode.org/dom/events/change.html,

change event only fires if its form field

e.g. input textarea and select

so change event will not fire when contents of div is changed.

N30
  • 3,463
  • 4
  • 34
  • 43
  • can you mark my reply as answer and upvote if its useful? thanks. – N30 Jun 29 '12 at 20:32
  • We did the following code but it still not working what is it missing ? http://stackoverflow.com/questions/11268382/yui-modifying-and-detecting-changes-of-a-div – Lucas Cabral Jun 29 '12 at 20:48