Validate Input Box Values

Marco Rainaldi shared this question 1 week ago
Answered

I'm looking for some scripting help on the forum here. I have the following GGB file that I'm trying to work with here:

https://www.geogebra.org/m/kgddnjh3

I'm trying to get the background of the input boxes to change to red/green depending on whether or not the value entered is correct or not. I'm not having much luck.

I've tried the following for the input box m<FCD with no luck.

If[a5==mangleadh,SetBackgroundColor[InputBox5,Green],SetBackgroundcolor[InputBox5,Red]]

I'm sure there is something simple I'm not noticing. If you could help me out, that would be great.

Thanks!

Comments (14)

photo
1

Have you tried If[a5==mangleadh,SetBackgroundColour[InputBox1,"Green"],SetBackgroundColour[InputBox1,"Red"]]

see """"""""""

Green is a predefined "Green" is a color

be carefull with color and colour (english or american)

photo
1

In the Geogebra Manual, the script command is "SetBackgroundColor" for US, which is what I'm using. I also tried colour, and it didn't work.

I also put the color in quotation marks and it still doesn't work properly. The background color of the input box will change to red, but when the correct value is entered, the background color does not change to green.

photo
1

puedes ver como el color no es problema en el adjunto así que el problema puede ser otro

Files: foro.ggb
photo
photo
1

Arreglado el a1 en tu archivo

primero es conveniente que los a. sean ángulos en lugar de números


comparar números con entradas enteras debe tener en cuenta el redondeo ; mira el script de a1

el problema ya no está en la instrucción color

puedes volver a seleccionar el redondeo a cero cuando todo esté correcto

photo
1

@mathmagic the script is better this way round

SetBackgroundColor(InputBox1,If(a5==mangleadh,"Green","Red"))

@Marco try this - you might like to try the new symbolic Input Boxes (try entering a fraction)

https://www.geogebra.org/m/vcxnhpre

photo
1

Thanks for all your feedback. I like the symbolic inputbox!

I have tried all the suggestions, and I believe they should work, but they are not. I modified Michael's file to demonstrate the issue.

@Michael - I think the problem is that I'm getting the value of mangleadh by dividing an angle by the degree symbol, and for some reason the boolean test comes out false when you compare a5 == mangleadh.

Is this an object type mismatch issue?

photo
1

I adviced you

abs(a5 < mangleadh)<0.02 instead a5 == mangleadh.

photo
1

The value of mangleadh changes when the New Exercise button is clicked, so a5 may not be less than mangleadh. And for some reason, when I use abs(a5 - mangleadh)<0.02 this does not do what I want it to do either.

photo
1

when I use abs(a5 - mangleadh)<0.02
please post the updated .ggb file - we can't guess what change you made exactly

photo
1

@Michael - I made the following change to a1 in the attached GGB file:

SetBackgroundColor[InputBox1,If[abs(a1-mangleadh)<0.02,"Green","Red"]]

photo
1

Your file is working - you need to enter the angle more accurately (eg 2 decimal places) - or increase the 0.02

or you could say

round(mangleadh)==round(a1)

photo
1

Thank you all for your help! I appreciate it very much!


I have it up and running as I had intended it to work: https://www.geogebra.org/m/kgddnjh3

I did have to adjust the 0.02 up to 0.6. I will also tinker around with round as well.

photo
photo
1

try the one indicated

photo
1

Thank you all for your help! I appreciate it very much!

I have it up and running as I had intended it to work: https://www.geogebra.org/m/kgddnjh3

photo
© 2021 International GeoGebra Institute