Change global variables through buttons?

HenriAugusto shared this question 7 years ago
Answered

Hi!


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:

alert(stringtest)

and i have an "Change global var":

stringtest = "new text!"

alert(stringtest)

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)

photo
1

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.


Greetings

Raymond

https://ggbm.at/1388195

photo
1

Hey, rami, thanks for your time!


That indeed worked flawlessly.


Thank you! :D

© 2022 International GeoGebra Institute