Hi
I've got a little script that adds up values for checkboxes to give a total. I'd like to insert a couple of radio buttons in there too. I need to give them a different name to the check boxes, otherwise selecting a radio box deselects the ticks in the checkboxes.
So I currently have
Code:
<script type="text/javascript">
function checkTotal() {
document.listForm.total.value = '';
var sum = 0;
for (i=0;i<document.listForm.choice.length;i++) {
if (document.listForm.choice[i].checked)
{
sum = sum + parseInt(document.listForm.choice[i].value);
}
}
document.listForm.total.value = sum;
}
</script>
<form name="listForm">
<input class="checkbox" type="checkbox" name="choice" value="4" onclick="checkTotal()">4
<input class="checkbox" type="checkbox" name="choice" value="5" onclick="checkTotal()">5
<input class="checkbox" type="checkbox" name="choice" value="10" onclick="checkTotal()">10
<input class="radio" type="radio" name="choice1" value="-20" onclick="checkTotal()">-20
<input class="radio" type="radio" name="choice1" value="5" onclick="checkTotal()">5
<input class="checkbox" type="checkbox" name="choice" value="10" onclick="checkTotal()">10
and realise that I need to change it to something vaguely like
Code:
if (document.listForm.choice[i].checked) andif (document.listForm.choice1[i].checked)
{
sum = sum + parseInt(document.listForm.choice[i].value) + parseInt(document.listForm.choice1[i].value);
except of course that is not valid code.
Any idea what I should be putting please?
thanks
Tony
Last edited by soon : 12-15-2006 at 07:46 AM.
Reason: making it clearer
|