Link to home
Start Free TrialLog in
Avatar of arthrex
arthrexFlag for Germany

asked on

Observe variable >> need to get "on change event"

Hi experts,

I have a global variable which is false.
I need to know when it changes to true.
Please no solution with while-loop.

Thanks a lot!
Avatar of culprit
culprit

you're using javascript ?
Avatar of arthrex

ASKER

yes I do
Avatar of contactkarthi
use setTimeout to call a function every N seconds. in that function check the values of the boolean variable. if it changes show an alert

http://www.techiwarehouse.com/cms/engine.php?page_id=3e7a2280

have a look at the above url for example
Avatar of arthrex

ASKER

thanks a lot.
but I'm more searching for something like event.observe(element,"change",function(){...});
the problem is that in DOM2 there is no eventname "change" for a variable, just for form elements.
You need the watch method, but is not cross- browser compatible (as far as I know):
http://www.devguru.com/technologies/ecmascript/quickref/watch.html
ASKER CERTIFIED SOLUTION
Avatar of Warpseh
Warpseh
Flag of Argentina image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of arthrex

ASKER

thanks for the response. well I need a cross-browser solution so the Observer part looks in general fine but not for my requirement, cause class A sets the value on its own

class A {
public boolean watchme = false;
}

class B {
// if A.watchme changes to true then dosomething
}
Avatar of arthrex

ASKER

Thank you all very much  for your responses.
At the end I used Warpseh's solution slightly modified.