How to reduce and add value from different element after we check and uncheck using checkbox in javascript?

I

Ihsan

Guest
When I check it can add some values in just 1 element, but I don't know how to add from different element and reduce it.


var y = 1;

function calc() {
if (document.getElementById("t1").checked) {
document.getElementById("demo").innerHTML = z = y + 1;
if (document.getElementById("t1").reversed) {
document.getElementById("demo").innerHTML = z = y - 1;
}
}
if (document.getElementById("t2").checked) {
document.getElementById("demo").innerHTML = z = y + 1;
if (document.getElementById("t2").reversed) {
document.getElementById("demo").innerHTML = z = y - 1;
}
}
}

<input id="t1" type="checkbox" name="model" value="a1" onclick="calc();">a1
<input id="t2" type="checkbox" name="model" value="a1" onclick="calc();">a2
<h1 id="demo"></h1>

Continue reading...
 
Top