samedi 6 mars 2021

How can I get the proper value of my checkbox instead of Null?

Currently I'm building a product page that has multiple filters in it. I want to get the value of my checkbox when it is checked by the user so I can display my code when checked. Have added a console.log to check it but only returns the error that it cannot read property of Null. What am I doing wrong?

My HTML

<h4>Some title</h4>
        <label class="container-filter">15 - 30 min.
                <input type="checkbox" value="15">
                <span class="checkmark"></span>
              </label>
        <label class="container-filter">30 - 60 min.
                <input type="checkbox" value="30">
                <span class="checkmark"></span>
              </label>

My Javascript

var input = document.querySelectorAll("input");
inputs.forEach(item => {
    item.addEventListener('change', function() {
    var checkedValue =  document.querySelector('.boardgame:checked').value;
        console.log(checkedValue)
 });
});



Aucun commentaire:

Enregistrer un commentaire