How can I change an input text field from a script?

Sander Tacker shared this question 6 months ago
Answered

After pressing a button, I want an input text field MyInput to get an initial text (respectively to be cleared). In the click routine of the button I tried the Java statements

ggbApplet.setValue("MyInput","New Text")
resp.

ggbApplet.setValue("MyInput","")


but both statements don't change the value of MyInput at all (see attachment).


What's the correct way to change / to clear an input text field from a script?

Comments (7)

photo
1

Why not use the simple GeoGebrascript with the command SetValue(text,"New Text" ) or SetValue(text,"" ) as command? start with defining the Inputfield as Inputfield(text) with text = "" instead of Inputfield().

So you already have got a text, and you can give it another value.


chris

photo
1

The reason is that my script is pretty complex and needs java script functions to create the next question for the user (calculate next coordinate system, generate certain random numbers in a loop and so on). To prepare for the answer the input field needs to get cleared resp. to get an initial string to be manipulated by the user.


Isn't there a way to do it in a java script?

photo
1

Using the escape sign ( \ ) of JavaScript I found a statement myself that works in JavaScript:


ggbApplet.evalCommand("SetValue(MyInput,\"New Text\")")
respectively


ggbApplet.evalCommand("SetValue(MyInput,\"\")")
to clear the input text field.


It looks a bit ugly and I think, it would be clearer to use ggbApplet.setValue instead, but it works.

photo
1

Try

setTextValue(String objName, String value)

photo
1

No, that seems to change the input text not at all:

ggbApplet.setTextValue("MyInput","New Text")

photo
photo
1

It is clear, that you have to write to linked text variable (Test)?

ggbApplet.setTextValue("Test", "NewText4InputBox1")


/LqCTz+7AwAAr179AV98cc+Veb38D+IZ5OtV5sukAAAAAElFTkSuQmCC

photo
1

Oh, you're right, I missed to change the linked variable. Now it works!

photo
© 2019 International GeoGebra Institute