checkboxesa group select all

Pkoll 10 Dec, 2024

Hi Max,

I have a Ckeckbox group and I want to have the possibility to "select all". How can I do that?

Can you help me?

Greetings

Paul

Max_admin 10 Dec, 2024

You need to use some javascript code in a JavaScript view:

document.querySelector("input[name='checkoboxes-name']").forEach(check => {
check.checked = true
})

this code should run when your select all checkbox or button is clicked

Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Pkoll 11 Dec, 2024

Hi Max,

I have this simple form with your javascript, but nothing changed. What is the problem and what do I wrong?

checkboxesa group select all image 1

Paul

Max_admin 11 Dec, 2024

the code should be inside an event listener:

document.querySelector("#id").addEventListener("click", e => {
    document.querySelector("input[name='checkoboxes-name']").forEach(check => {
        check.checked = true
    })
})

where #id is the id of the field to be clicked, you need to change this based on your requirements

Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Pkoll 12 Dec, 2024

Hi max,

I have tried all kind of triggers etc..

Can you please send me a working example how to use javascript te change the checkboxes.

Paul

Max_admin 13 Dec, 2024
Answer

I tested the following code and is working:

document.addEventListener("DOMContentLoaded", function (event) {
    document.querySelector("[name='checkbox_2']").addEventListener("change", e => { // checkbox_2 is the name of the master checkbox
        document.querySelectorAll("input[name='checkboxes_3[]']").forEach(check => { // checkboxes_3[] is the name of the other checkboxes
            Nui.Checkbox.getInstance(check.closest(".nui.checkbox")).toggle()
        })
    })
})

I have also added "Select All" to the list of Listener actions which can be fired on triggers

Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Pkoll 13 Dec, 2024

Thanks Max

it works

Paul

You need to login to be able to post a reply.

VPS & Email Hosting 20% discount
hostinger