vendredi 22 mai 2020

HTML Template string : input tag type checkbox

I need to create a checkbox input for each element of myObject, I decided to use Template literals for this:

function checkTemplate(myObject){
    var checkboxDiv = checkboxesArtist;
    checkboxDiv.innerHTML=`
        ${myObject.map(function(art){
            return `
            <div class='form-check'>
                <label class='form-check-label' for='${art.id}'>
                    <input class='form-check-input artist_opinion' id='${art.id}' 
                    type='checkbox' name='${art.name}' value='${art.id}'/>
                    ${art.name}
                    <small class='text-secundary'>${art.count}</small>
                </label>
            </div>   
        `
        }).join('')} 
    `
} 

How can I access the state of each checkbox? I try to create an array by

input = document.getElementsByClassName('form-check-input artist_opinion');

If I do console.log(input), I can see the HTML Collection Array with all the elements, however with the note 'Value below was evaluated just now' and if I do console.log(input.length), that is 0. So I do not know how to access elements created with the above code snippet, in particular, how to check the value of the checkbox.




Aucun commentaire:

Enregistrer un commentaire