Change global variables through buttons?

HenriAugusto shared this question 7 years ago


There is any way of changing the value of a global variable through a button?

Read the following only if you want an example: Let's say i have in my Global Javascript

var stringtest = "initial text"

and i have a "Alert Global" which is:


and i have an "Change global var":

stringtest = "new text!"


When i click "Alert global" it gives me "initial text".

Then i click "Change global var" and it indeed gives me "new text!". But, after clicking "Change global var", if i click "Alert global" again it still gives me "initial text". It's like the "Change global var" button replace localy the stringtest variable but doesn't change it globaly.

So here is my question: is there any way to change a global variable through a button so it's value will be accessable through the entire applet?

Comments (2)


Hi Henri

Only in the global Java-Script you can set a global variable.

It's is possible to go from a OnClick or OnUpdate-Script to global JavaScript with a function. The attachment show one possibility.




Hey, rami, thanks for your time!

That indeed worked flawlessly.

Thank you! :D

© 2022 International GeoGebra Institute