Function to dynamically uncheck or untick a checkbox or radio button

phicts 04 Feb, 2016
How can I dynamically uncheck or untick a checkbox or radio button in the events tab of another field? Any code please or is there a built-in function for this in chronoforms version 5?

The simplest scenario is like this:

Checkbox 1 (field ID is checkbox1):
A. It is unticked by default on page load
B. When Checkbox 1 is checked, it shows a hidden container that contains other fields including Checkbox 2

Checkbox 2 (field ID is checbox2):
A. Checkbox 2 displays/hides other fields
B. When checked or ticked, it should set Checkbox 1 back to unticked status.

Thanks in advance for any pointer.
GreyHead 04 Feb, 2016
Hi phicts,

You can certainly do the first part of this with the Events tab in the Checkbox element.

The second part makes no sense to me - if checking Box 2 unchecks Box 1 then logically that will also re-hide box2 and the other fields in the container??

Bob
phicts 04 Feb, 2016

Hi phicts,

if checking Box 2 unchecks Box 1 then logically that will also re-hide box2 and the other fields in the container??

Bob


Exactly, we want to rehide checkbox2 and the container.

We actually want to apply the same code to checkbox1 so that checkbox2 will be unticked.

We also need to learn the function/code for other purposes, not just in the example scenario here.

Thank you.
GreyHead 04 Feb, 2016
Hi phicts,

That's a bit like one of those puzzle boxes where you have a switch to open it and a hand comes out and flips the switch to close the box again. [ [url=https://www.youtube.com/watch?v=Z86V_ICUCD4]YouTube[/url] ]

Please explain to me how this works, you check Box 1 to show Box 2 and checking Box 2 hides itself and un-checks Box1??

I'm sure that you can do this with a few lines of JavaScript. Here's an example I found on StackOverFlow
var check;
$("#test-with-prop").on("click", function(){
    check = $("#mycheckbox").prop("checked");
    if (check) {
         alert("Checkbox is checked.");
    } else {
        alert("Checkbox is unchecked.");
    }
}); 

Bob
phicts 04 Feb, 2016
No alert or notification needed, just the function to untick each other.
Ok, my scenario looks like crazy, funny or whatever. So please just forget the logic for the meantime; consider it a crazy trick. It will sound logical in other scenario like unticking or resetting at once a number of checkboxes. But IDK how to do it.
GreyHead 04 Feb, 2016
Hi Phicts,

You'd replace the alert line with the code to do whatever it is you need to do. It's just an example.

Bob
This topic is locked and no more replies can be posted.