dimanche 5 novembre 2023

How to check all checkboxes on one field? using JS

I have one field that has 5-6 checkboxes (and will increased more in the future), this field name email_notification, here's the code that i find on google to automatic check all the check boxes on event Form - On Load.

var checkboxes = document.querySelectorAll('input[type="checkbox"]');
checkboxes.forEach(function(checkbox) {
    checkbox.checked = true;
});

When I run the code, it will auto check all my checkboxes on field email_notification, it also check all checkboxes on other field. I just want only one field to automatically check all the checkboxes. Is there any clue to change the syntax? Thank you for helping.

I'm not familiar with Javascript, and I've been googling about this on one week but didn't find any clue.




Aucun commentaire:

Enregistrer un commentaire