flip checkboxes by script

Werner Knobloch shared this question 5 years ago
Answered

Hello,

I'm trying to create a system of two checkboxes, that interact with each other in the following way:

Exactly one checkbox must always be selected "checked". Both checkboxes must be seen.


My construction works, but from time to time the system gets out of rythm. Then both checkboxes

are unchecked or checked at the same time.

I'm not so practised in scripting. Is there a method that is more secure ?


Cheers,

Werner


a817062bcc9f012feb4491d6d8389cbd

https://ggbm.at/1576839

Comments (7)

photo
1

hello

i think this more stable

saludos

https://ggbm.at/1576841

photo
1

Ich antworte mal faulerweise auf deutsch:


Was du da angefangen, sieht verwirrend aus. Selbst du JS verwendest, solltest du mit einem einfachen GGB-Script zurecht kommen:

Wenn ich zwei Kästchen "a" und "b" habe, so schreibe ich bei "a" als Update-Script: SetzeWert[b,!b] und umgekehrt bei "b".


Vorraussetzung: a ist aktiv und b inaktiv in dem Moment, wo man das einträgt.

photo
1

@Birgit

I had this simpler solution in the beginning. But then I noticed that there is a timing problem if you change

or click to fast or if you have much programming code / source code. Therefore I tried the solution with storing in Modus_{store}. Seems this was just a helpless try to make things better. The problem was still there or even got worse, thats why I asked for help.


Danke Werner


@mathmagic

Your solution is much more stable but you have to change the checkbox everytime you want a change.

So, if I don't get the perfect solution , I think this solution will do it.


saludos Werner

photo
1

Hi,


Try script in Modus_1

    SetValue[Modus_2,!Modus_1]

and in Modus_2

    SetValue[Modus_1,!Modus_2]

Simon

photo
1

@slik


Your code ist perfectly stable !


In the meantime I got another solution from Roman Chijner that seems also perfecly stable.


script in Checkbox a

    SetzeWert[b,Wenn[a==true,false,true]]

script in Checkbox b

    SetzeWert[a,Wenn[b==true,false,true]]

Thank you all

Werner

photo
1

Yes it will be stable but If[] commands are not necessary with boolean output. The first one will work just as well with

    SetzeWert[b,!a]

all the original says is "if a is true then false but if a is false true" in other words "not a" 8)

Simon

photo
1

By the way, you can use the same scripts to work with more than two checkboxes or to make things like radio buttons.


Simon

https://ggbm.at/1576843

© 2021 International GeoGebra Institute