Javascript Sum Drop Down Values
Ray - I have downloaded a simple javascript that adds up the values for multiple checkboxes on a page if the visitor checks the boxes - this works fine - and it displays the total on the same page...
Here is the function, script and HTML:
<script type="text/javascript" src="autoSumCheckboxes.js"></script>
function UpdateCost() {
var sum = 0;
var gn, elem;
for (i=0; i<29; i++) {
gn = 'prod'+i;
elem = document.getElementById(gn);
if (elem.checked == true) { sum += Number(elem.value) }
}
document.getElementById('totalcost').value = sum.toFixed(2);
}
<td><input type="checkbox" id='prod1' value="425.00" onclick="UpdateCost()" />
$ 425.00</td>
</tr>
<tr>
<td>T-5208-34M or L</td>
<td colspan="2">Helmet Impact Liner, medium or large</td>
<td><input type="checkbox" id='prod2' value="245.00" onclick="UpdateCost()" />
$ 245.00</td>
I now need to set up a drop down (select list) that will do the same for the values in the select list..
This does not work and the total field is blank:
<td width="169"><form id="form1" name="form1" method="post" action="">
<label>
<select name="joe" id="prod0" onchange="MM_callJS('UpdateCost()')">
<option>select</option>
<option value="100.00">one</option>
<option value="200.00">two</option>
</select>
</label>
</form></td>
I'm sure the function and select list has to change but I've tried several times - no luck...
Suggestions?
thanks in advance....