Hey guys i have a question about calculating checkboxes and its total in real time so here is my code:
function calc()
{
theTotal = 0;
checkForm = document.FormName;
for (i=0; i <= checkForm.length-1; i++) {
if (checkForm.elements[i].type == "checkbox") {
if (checkForm.elements[i].checked == true) {
document.getElementById("total").value = theTotal;
}
}
}
document.getElementById("total").innerHTML = theTotal;
}
Here is my html code:
<p>Total: $<span id="total">0</span></p>
<tr>
<td> <br> <center> <img src="Shirt1.jpg" width="160" height="150" alt="shirt1"> <br> <input type="checkbox" onchange="calc()" value="19.99"> <label for="rd1">Obey T-Shirt: $19.99</label> </center> </br></td>
<td> <br> <center> <img src="Shoe1.jpg" width="160" height="150" alt="shoe1"> <br> <input type="checkbox" onchange="calc()" value="19.99"> <label for="rd1">Shoe - Red Lace: $19.99</label> </center> </br> </td>
<td> <br> <center> <img src="Snapback1.jpg" width="160" height="150" alt="snap1"> <br> <input type="checkbox" onchange="calc()" value="19.99"> <label for="rd1">Snapback Bullets: $19.99</label> </center> </br> </td>
</tr>
When i click on one of the selected checkboxes it won't give me the calculation that i want. Are you able to help me with this one?