mercredi 19 août 2020

How to add an element to an array when a checkbox is checked

I would like that when I check a checkbox, an element is added to the array, and when I uncheck the check box. The code is working, but not properly, and I can’t figure out where it came from.

var tableau= ["0"];

var checkBox_numero = document.getElementById("numero");

    checkBox_numero.addEventListener('change', function () {
        if (this.checked) {
            // Checkbox is checked..
            tableau.push("numero");
        } else {
            // Checkbox is not checked..
            tableau.shift();
        }
    });
    console.log(tableau);




Aucun commentaire:

Enregistrer un commentaire