0
I’m trying to add value values that were selected via checkbox with pure Javascript. What I’m missing ?
Follow the line of code I rationed ...
HTML
<h2>Escolha seus destinos:</h2>
<input type="checkbox" class="passagem" value="780.00">
<label for="pais1">Peru</label>
<input type="checkbox" class="passagem" value="960.00">
<label for="pais2">Chile</label>
<input type="checkbox" class="passagem" value="870.00">
<label for="pais3">Bolivia</label>
<input type="checkbox" class="passagem" value="910.00">
<label for="pais4">Uruguai</label>
<input type="checkbox" class="passagem" value="980.00">
<label for="pais5">Argentina</label>
<hr>
<div>
<input type="checkbox" class="passagem" value="350.00">
<label for="voltar">Deseja passagem de volta ao Brasil?</label>
</div>
<button onclick="calcular()">Calcular</button>
<p class="resultado"></p>
Javascript
function calcular () {
document.addEventListener('click', function() {
var peru = document.querySelectorAll('input[valeu="780.00"][type="checkbox"]:checked').length;
})
document.addEventListener('click', function() {
var chile = document.querySelectorAll('input[valeu="960.00"][type="checkbox"]:checked').length;
})
document.addEventListener('click', function() {
var bolivia = document.querySelectorAll('input[valeu="870.00"][type="checkbox"]:checked').length;
})
document.addEventListener('click', function() {
var uruguai = document.querySelectorAll('input[valeu="910.00"][type="checkbox"]:checked').length;
})
document.addEventListener('click', function() {
var argentina = document.querySelectorAll('input[valeu="980.00"][type="checkbox"]:checked').length;
})
document.addEventListener('click', function() {
var voltar = document.querySelectorAll('input[valeu="350.00"][type="checkbox"]:checked').length;
})
var passagem = parseInt(peru) + parseInt(chile) + parseInt(bolivia) + parseInt(uruguai) + parseInt(argentina) + parseInt(voltar);
document.querySelector('.resultado'). innerHTML = passagem;
}
Does the answer to this question help you? https://answall.com/questions/83463/pega-valores-checkbox-com-javascript?rq=1
– Emerson Pardo
input[valeu="350.00"] is valeu or value?
– adventistaam