PDA

View Full Version : Watching variables



???
08-31-2007, 02:52 PM
I was just wondering how you have basically an event attached to a variable. So when it changes a function is called. Can it be done, and if so is it cross browser?

jscheuer1
08-31-2007, 05:13 PM
You can use a poll, which is a looping function (using setInterval or setTimeout) that periodically checks the value of the variable involved and then does something if it changes. However, in almost all cases, it is better to simply have the event or script code that changes the variable's value in the first place also do whatever needs to be done when that variable is changed.