vendredi 29 août 2014

Data not capturing correctly


Vote count:

0




I have tried the below DEMO to set value for checkboxes as "0" or "1" based on selection of checboxes. The below code is working for one checkbox but If I create multiple checkboxes, it is not working for new ones. How to make it work for all checkboxes.



HTML:
<input type="checkbox" value="1" />Checkbox
<br/>
<br/>
<span id="result"></span>

JS:
window.onload = function () {
var input = document.querySelector('input[type=checkbox]');

function check() {
if (input.checked) {
var a = "1";
} else {
var a = "0";
}
document.getElementById('result').innerHTML = 'result ' + a;
}
input.onchange = check;
check();
}


DEMO



asked 1 min ago







Data not capturing correctly

Aucun commentaire:

Enregistrer un commentaire