Scripting in GeoGebra
Script is a sequence of commands, that are executed one after each other.
GeoGebra supports two scripting languages - GGBScript and Javascript. You enter scripts in the Scripting tab of the
Properties Dialog of the object you want to assign a script to.
Note: The Properties panel needs to be closed for scripts to work.

Different objects support different types of scripting; the execution of scripts can be triggered by:
- clicking a particular object (OnClick tab)
- updating a particular object, when value or properties of the object are changed (OnUpdate tab)
- changing the content of an input box (OnChange tab)
- when the mouse button is released (or finger is removed from the screen for touch devices) after dragging an object (On Drag-end tab)
- loading the file (for JavaScript - Global Javascript tab)
- Javascript listeners (see Reference:JavaScript)
- Check the demo of OnChange and OnUpdate scripts for an input box.
- Check the demo of OnDrag-end scripting for a draggable point.
GGBScript
You can create scripts consisting of GeoGebra commands, as you would use them in the Input Bar. After triggering the script, every command is executed, in the same order they are written, sequentially.
Example:
- is an integer-valued slider ranging from to (therefore Increment equals )
- type in:
list1 = {"red", "green", "blue"}
- in properties of , set "On Update" script to
SetColor(a, Element(list1, a))
- by moving the slider you change its color
JavaScript
JavaScript is a programming language used by many Internet technologies. Unlike GeoGebra Script, in Javascript commands don't have to be executed as a simple sequence, but a control flow (
This script creates 10 points to at random coordinates.
Note: Scripting with JavaScript is very versatile, but many tasks can also be achieved using the simpler GeoGebraScript.
if
, while
, for
) can be used. For generic JavaScript you can find a nice tutorial on developer.mozilla.org. 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 a complete list of these methods see Reference:JavaScript.
Example:
for(var i =0;i<10;i++)
ggbApplet.evalCommand("A_"+i+"=(random()*10,random()*10)");
Global JavaScript
In the Global JavaScript part of the Scripting tab in the
Properties Dialog you may define functions (not variables) which will be available from the other scripts. You can also define function ggbOnInit(name, api), which is called automatically once the construction is loaded. The ggbOnInit function can be used for registering some listeners, as shown below.
Example:

function onAdd(name){
alert("Object "+name+" was added.");
}
function ggbOnInit(name, api){
api.registerAddListener("onAdd");
}
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. , message "Object A was added" will appear.
You can also use listeners for actions like rename, delete and clear construction. A 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.