arthrex
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!
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!
you're using javascript ?
ASKER
yes I do
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
http://www.techiwarehouse.com/cms/engine.php?page_id=3e7a2280
have a look at the above url for example
ASKER
thanks a lot.
but I'm more searching for something like event.observe(element,"cha nge",funct ion(){...} );
the problem is that in DOM2 there is no eventname "change" for a variable, just for form elements.
but I'm more searching for something like event.observe(element,"cha
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
http://www.devguru.com/technologies/ecmascript/quickref/watch.html
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
}
class A {
public boolean watchme = false;
}
class B {
// if A.watchme changes to true then dosomething
}
ASKER
Thank you all very much for your responses.
At the end I used Warpseh's solution slightly modified.
At the end I used Warpseh's solution slightly modified.