From GeoGebra Manual
Revision as of 13:26, 6 November 2011 by Birgit Lachner (talk | contribs)
Jump to: navigation, search

Scitps are a sequence of commands, that are executed one after each other. GeoGebra supports two scripting languages - GGBScript and Javascript. The execution can be triggered by :

  • clicking or updating (new value or redefinition) a particular object
  • loading the file (in case of JavaScript)
  • Javascript listeners (see Reference:JavaScript)

You can set this script via Scripting panel of Properties Dialog.


You can create scripts consisting of GeoGebra commands.

  • a is an integer-valued slider ranging from 1 to 3
  • list1 = {"red", "green", "blue"}
  • in properties of a, set "On Update" script to SetColor[a, Element[list1, a]]
  • by moving the slider you change its color


JavaScript is a programming language used by many Internet technologies. Unlike GeoGebra Script, in Javascript the commands don't have to be executed as a simple sequence, but a control flow (if, while, for) can be used. For generic JavaScript you can find a nice tutorial on In GeoGebra, you can use special JavaScript methods which allow you to change the construction. These methods belong to ggbApplet object, which means that you call them as ggbApplet.method_name(parameter,..,parameter). For complete list of these methods see Reference:JavaScript.

for(var i =0;i<10;i++) 
This script creates 10 points A0 to A9 at random coordinates.

GeoGebra contains its own JavaScript engine. When exported as Dynamic Worksheet one can choose whether to use this engine or the one contained in browser applets. If you edit JavaScript in a HTML page, the ggbApplet variable will not be initialized, you have to initialize it e.g. using ggbApplet=document.applets[0]; first.

Global JavaScript

In the Global JavaScript part of Scripting tab in Properties Dialog you may define some functions or do some assignments that will be done before the construction is loaded. You can also define function ggbOnInit(), which is called automatically once the construction is loaded. The ggbOnInit function can be used for registering some listeners, as shown below.

function onAdd(name){
    alert("Object "+name+" was added.");

function ggbOnInit(){
First we defined function onAdd that given a string shows a message depending on that string. After that, using the ggbOnInit function, we told GeoGebra to call this function whenever a new object is added. Once we reload our construction, function ggbOnInit will be called and since then, when user adds a point named e.g. A, message "Object A was added" will appear.

You can also use listeners for actions like rename, delete and clear construction. Complete list is available in Reference:JavaScript.

Note: Using any ggbApplet methods in Global JavaScript outside of ggbOnInit will not work as intended since they will be called before the construction is loaded.

USB Data Logging (From GeoGebra 4.2)

For logging data from some Vernier USB Data Loggers, eg Go!Motion and Go!Temp one can define a logger listener using the registerLoggerListener method. Such listener can look like this:

function logger(value) {
   var d = value * 1;

This script assumes that there is a free number a in the construction. Each time number d is logged, point (a,d) is constructed and a is increased.


© 2022 International GeoGebra Institute