You can use the pseudo-selector :checked
which is part of the W3C specification. Natively, no libraries.
Using document.querySelectorAll('input:checked');
You get a list of items that are marked.
In your code you could use it like this:
var confirma = document.getElementById('confirma');
var resultado = document.getElementById('resultado');
confirma.addEventListener('click', function() {
var checkados = document.querySelectorAll('input:checked');
resultado.innerHTML = [].map.call(checkados, function(el){
return el.value;
}).join(', ');
});
If you want to use the jQuery API for example you can do so, using also the :checked
but of jQuery:
$('#confirma').on('click', function() {
var valores = $('input:checked').map(function() {
return this.value;
}).get().join(', ');
$('#resultado').html(valores);
});
Yes, I never remember how you do it and I always turn to the Web. Good question.
– Marconi