Getting State of Objects using Javascript

Lew W. S.


The applet presented below help to demonstrate a few simple examples of how Javascript in Geogebra is used to get the state of objects. In particular the script commands used are : State Object getValue - value in a number variable getValueString - text  in a textbox getCaption - caption of a button The above commands are found in Geogebra Manual's section on Reference:Javascript


Script in button1's On Click SetValue[n,If[n<4,n+1,1]] script command in button2 On Click : value1 = ggbApplet.getValue('n'); alert("1. n = "+value1+" now"); script command in button3 On Click : text2 = ggbApplet.getValueString('textTitle'); alert("2. textTitle contains the string : \n"+text2); script command in button4 On Click text3 = ggbApplet.getCaption('button1',false); alert("3. The caption of button1 now is : "+text3); For the getCaption() command, the second parameter - boolean must be included. false - if no substitution values eg. %v, %n, are used true - if you need to extract the substitution values eg %v, %n]