I am trying to do some JavaScript calculation with checkboxes, and have been able to modify some codes to do bits of what i want to do. (Screenshot attached)
However, i want each checkbox to have multiple values, and therefore multiple results.
I can't find any examples, but i've come across something similar with Radio buttons (http://javascript.about.com/library/blmulti1.htm). I don't 'get' the example enough to proceed.
My question is, is it even possible to do with a checkbox, and if so how do i go about doing it please? Any help would be greatly appreciated.
The Javascript code:
function count() {
var item1price = 10;
var item2price = 50;
var item3price = 1100;
var item4price = 100;
if (calc.item1.checked){
var witem1 = document.calc.item1.value = item1price; }
else {
var witem1 = document.calc.item1.value = 0; }
if (calc.item2.checked){
var witem2 = document.calc.item2.value = item2price; }
else {
var witem2 = document.calc.item2.value = 0; }
if (calc.item3.checked) {
var witem3 = document.calc.item3.value = item3price; }
else {
var witem3 = document.calc.item3.value = 0; }
if (calc.item4.checked) {
var witem4 = document.calc.item4.value = item4price;}
else {
var witem4 = document.calc.item4.value = 0; }
document.getElementById('pay').innerHTML = witem1 + witem2 + witem3 + witem4;
}
The HTML form:
<form name="calc" method="POST">
<br />
<table class="gqra">
<tr>
<td class="row2" ><span> Item </span></th>
<td class="row2" ><span> Select </span></th>
</tr>
<tr>
<td class="row"><span> Item 1 </span></td>
<td class="row"><input type="checkbox" name="item1"></td>
</tr>
<tr>
<td class="row"><span> Item 2 </span></td>
<td class="row"><input type="checkbox" name="item2"></td>
</tr>
<tr>
<td class="row"><span> Item 3 </span></td>
<td class="row"><input type="checkbox" name="item3"></td>
</tr>
<tr>
<td class="row"><span> Item 4 </span></td>
<td class="row"><input type="checkbox" name="item4" ></td>
</tr>
<tr>
<td class="row"> </td>
<td class="row">
<input type="button" onClick="count()" value="Calculate" >
<input type="reset" value="Reset" >
</td>
</tr>
<tr>
<td class="row"> Total price, $: <span id="pay"></span> <br /> </td>
<td class="row"> </td>
</tr>
</table>
</form>