Checkbox clicked if totalCount is equal to number field in Database else checkbox unclicked

Hi

Here below is my code for counting number of repeaters generated by a user.

I have a checkbox on Dynamic page and a number field with field value num. How can I have checkbox clicked when totalCount is equal to number field? Could any please help me?

setTimeout ( function () {
let totalCount = $w ( “#dataset1” ). getTotalCount ();
$w ( ‘#text250’ ). text = totalCount . toString () + " TRAVELERS JOINED"
}, 5000 );

Hi,

If you’re using the Checkbox element, you can set that element’s “checked” property to be true.
For example,

if(totalCount === num) {
    $w("#myCheckbox").checked = true;
}

I am trying to limit number of comments on dynamic page. If totalCount is equal or greater than the number field, I want to set boolean field in collection to true. If boolean is true, then user cannot comment. This part I have already coded. I just want to set boolean field true when totalCount becomes equal to number field.

Sounds like you have the logic figured out, but your totalCount variable isn’t updating dynamically if I understand correctly.

To update your variable based on the number of comments, you’ll probably need some type of event listener like onChange.

Here below is my code. I don’t know why it is not working. Now I am not using any checkbox on dynamic page. When totalCount becomes greater than commentLimitCount, I want to set the boolean field commentsDisabled true. Could you please guide me how to do this?

function filterComments ( ) {
let page = $w ( “#dynamicDataset” ). getCurrentItem ();
let pageId = page . _id ;
$w ( ‘#dataset1’ ). setFilter (
wixData . filter ()
. contains ( “pageId” , pageId )
). then (() => {
let totalCount = $w ( ‘#dataset1’ ). getTotalCount ()
if ( totalCount > page . commentLimitCount - 1 ) {
$w ( “#dynamicDataset” ). setFieldValue ( “commentsDisabled” , true );
} else {
setTimeout ( function () {
}, 1500 );
}
});
}