dimanche 9 août 2020

Checkbox value only when checked

I'm trying to get the checkbox output to a variable x only when checked. Now it passes the value of checkbox even unchecked

 function myFunction(){
        
     var  x  =parseInt(document.getElementById('cough').value)+
     parseInt(document.getElementById('cold').value)+ 
     parseInt(document.getElementById('fever').value) + 
     parseInt(document.getElementById('breathlessness').value) +
     parseInt(document.getElementById('loss of senses').value) + 
     parseInt(document.getElementById('sore throat').value) +
     parseInt(document.getElementById('none').value) +
     parseInt(document.getElementById('diabeties').value)+
     parseInt(document.getElementById('heart disorder').value) +
     parseInt(document.getElementById('lung disorder').value)+
     parseInt(document.getElementById('kidney disorder').value) + 
     parseInt(document.getElementById('hypertension').value) + 
     parseInt(document.getElementById('no disorder').value);
        
          console.log(x)
    }

I need to get these values only when checked




Aucun commentaire:

Enregistrer un commentaire