problems with an optional checkbox

kraadde 1d ago

Max I have a dropbox and want a checkbox to be visibel depending on the data choosen live in the dropbox. I experimented with a script placed inside an html field between the dropbox and the checkbox like that:, but without success, the checkbox is always visibel. Where is the mistake?

<script>
document.addEventListener('DOMContentLoaded', function () {
    const dropdown = document.querySelector('[name="zusteige_ort"]'); // ← dein Dropdownname
    const checkbox = document.querySelector('[name="park_platz_tw"]');

    function toggleCheckbox() {
        checkbox.closest('.form-group').style.display = (dropdown.value === "Ruetihof") ? 'block' : 'none';
    }

    dropdown.addEventListener('change', toggleCheckbox);
    toggleCheckbox(); // Initialzustand
});
</script>

Max_admin 1d ago

Hi Kraadde

Why not use the Triggers & Listeners behavior for this ?

Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
You need to login to be able to post a reply.