Javascript w geogebrze

Sebastian shared this question 1 year ago


Mam problem z wykorzystaniem js w geogebrze, nie wiem jak odwołać się do np pola tekstowego w aplikacji, chce stworzyć aplikacje wyliczającą układy równań z kongruencją, w teori mam cały skrypt gotowy, ale gdy wszystko podpinam pod przyciski to po naciśnięciu w nie nic się nie dzieje, czy mógłby mi ktoś wyjaśnić czy ta funkcja w ogóle się odwoła do aplikacji?

function czysc(){

var g=ggbApplet;





mianowicie jak widać ma ona "wyzerować" pola tekstowe ale niestety nie działa. Ktoś coś? :)

Comments (12)


Please post your .ggb file


Sorry for the dealy. Maybe you can help me with this.


I delete the 2 functions-header in "przycisk3" (set with // as comment)

If the "On Click" event is fulfilled, all commands are executed in it.

But not the declarations of "function <name>(<parameter>,...)".

The functions must be call explizit with "<function-name>(<parameter>,..)"

It's difficult for me to understand the program in you language, so I'm not sure this is what you want do.


How to refer to the GlobalJavaScript? I have all the code there, but I do not know how to use it in the buttons. I have to prescribe it now on OnClick and on change?


In the button call the function in global JS with

<function-name>(param1, param2,.....)

In the global JS define:

function <function-name>(param1, param2,.....){

<JS commands>



for example: in your program exist in global JS the function "function czyscRownania(){......}"

you can call this function in JS of a button with "czyscRownania()"


consult also a JS manual maybe a JS tutorial

maybe make your own simple/small JS examples inside in GGB

I mean, without good knowledge of GGB AND JS, it's almost impossible to adapt a JS program to GGB.


ok i have that code

var g = ggbApplet;

var rownania = [

]; //tab rownanie

var x = g.getValue("px");

if (x === null || x === "") {

x = 0;


var y = g.getValue("py");

if (y === null || y === "") {

y = 0;


var z = g.getValue("pz");

if (z === null || z === "") {

z = 0;


var rownanie = [x, y, z]; // i need this in tab rownania

rownania.push(rownanie); //push [x,y,z] to tab rownania?

g.setTextValue("txtObliczenia", "");

g.setTextValue("txtWynik", "");

var txt = "\\left\\{ \\begin{array}{l} "; //start

for (var i = 0; i < rownania.length; i++) {

txt = txt + rownania[i][0] + "x ≡ " + rownania[i][1] + " ( mod\\, " + rownania[i][2] + " ) \\\\ ";


txt = txt + "\\end{array}\\right. \\\\";

g.setTextValue("txtRownania", txt); //end (that code write my [x,y,z] in txtRownania

why rownania.push(rownanie), dosn't push this on var rownania?


Why you think the script do this not?

To check this: use alert() after the push.


rownania.push(rownanie); //push [x,y,z] to tab rownania?

alert("rownania after push rownanie = " + rownania)


When I run the script in button "przycisk1" then the value show in the alert seems be OK




Quote: "why rownania.push(rownanie), dosn"t push this on var rownania?"

for me this last question was a bad question.

Please give a complete documentation to a question.


alert is ok, but i need insert [x,y,z] to var rownania;

in rownania i need something like that:


var rownanie =[







Then you must define the table in algebraview, because a JS (onUpdate||onKlick) has no istance variables (no memory when the script is finish)

Then the JS makes no sense because this is massively easier in GGB-Script.

Determine when a new list-element (with 3 values as list) is to push in a list for example with button.

Use the GGB-script commandl SetValue(<table>,<index>,<value>) to attach 1 element (push)

Note: <value> can be also a list: {px,py,pz}

Determine with which condition (eg button "Reset") the table should be initialized

Use Sequence() in the Algebra View to render the table into text

Use TableText() in the algebra-view to display the text-list in the graphic.


All this could be done in global-JS. But that's too complicated for me and I can not offer any support.


I do not understand how to do it, can I add GGB script to JS? So I understand that in JS I will not do to add values to the table and then unsubscribe them? And if I put these values ​​in three other variables? Only I would not write them out in TxtRownanie.


Sorry, see the last sentence here.


Didn't you just forget to call your function?

Try file below. It works.

© 2021 International GeoGebra Institute