Toggle checkmark button status [SOLVED]

I have a checkbox button, and I want to know when it is ‘checked’ or ‘unchecked’.

I’ve looked into the $w button documentation, but there is no apparent function for getting the enabled/disabled status of such a button, only actively changing it to be disabled or enabled…

Of course I use onClick at first, but then I have no way of knowing if the next onClick is to check or to uncheck it.


What you should do is write an onChange handler.
It will look like:

export function checkbox1_change(event, $w) {
 if ($w('#checkbox1').checked) {
        console.log("box now checked");
    } else {
        console.log("box now unchecked");

LMK if this works.

1 Like

Hi Reuven,
Thanks! that’s the functionality I expected :slight_smile:

I have many checkboxes and I want to make a function to which I pass function(checkboxID, string) and then do if ($w(‘#checkboxID’).checked) {…}

but I get an error that it’s “not a valid selector name” . Any way around that?

Scratch that - I was too quick to reply but I realized I could just pass the ID as a string and just do:
if ($w(checkboxID).checked) {…}

Thanks! Problem solved.