vendredi 20 novembre 2020

Button to appear or disappear based on checkboxes in Javascript

I have a column in a table that contains checkboxes so that the user can click multiple rows and delete the data. I have managed to make a delete button appear when the boxes are clicked by using a for loop. What I am struggling with is how to make the button disappear when the user un-checks all the boxes. I have banged my head against the wall for longer than I'd like to admit and I haven't found any previous questions that have been helpful. Thanks in advance for any input!

function memDeleteButton() {
    // Pass the checkbox name to the function
    let checkboxes = $('input[name=members]:checked');
    let deleteButton = document.getElementById("memDeleteSelected");

    // loop over all of the checkboxes
    for (let i = 0; i < checkboxes.length; i++) {

        if (checkboxes[i].checked = true) {
            deleteButton.style.display = "inline";

        }
        else if (checkboxes[i].checked = false) {
            deleteButton.style.display = "none";
        }
    }
}



Aucun commentaire:

Enregistrer un commentaire