Javascript w geogebrze

Sebastian shared this question 5 months ago
Answered

Witam.

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;

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

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

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

}


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

Comments (11)

photo
1

Please post your .ggb file

photo
1

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

photo
1

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.

photo
1

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?

photo
1

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.

photo
1

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?

photo
1

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

d020e419c5b220a48dc793e2695c96b5

.

PS:

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.

photo
1

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

in rownania i need something like that:

//--------


var rownanie =[

[x1,y1,z1],

[x2,y2,z2],

[x3,y3,z3]

];

//-----------

photo
1

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.

photo
1

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.

photo
1

Sorry, see the last sentence here.

© 2019 International GeoGebra Institute