PDA

View Full Version : totalling columns from radio button input & placing totals at foot of columns


NigD
02-13-2003, 09:34 PM
I am unable to write the totals of arrays back to text boxes at the foot of the form I'm using for the multiple choice test.

Each question has 4 possible answers, and I have grouped each set of 4 radio buttons as group0, group1, group2 etc.

The coding for the bottom of the form looks like this:
Calculate Totals
<input name="Calculate" type="button" onClick"score(this.form)" value="Calculate"></td>
<td><div align="center">
<input name="never" type="number" value="" size="4">
</div></td>
<td><div align="center">
<input name="seldom" type="number" value="" size="4">
</div></td>
<td><div align="center">
<input name="often" type="number" value="" size="4">
</div></td>
<td><div align="center">
<input name="always" type="number" value="" size="4">

The function score(this.form) looks like this:
function score(form) {
var f=document.forms['stress'];
var totals=new Array();
totals[0]=0;
totals[1]=0;
totals[2]=0;
totals[3]=0;
for (i=0;i<4;i++) {
for (j=0;j<5;j++) {
if (f.elements["group"j][i].checked) {
totals[i]++;
}
}
}
}
document.never.value=totals[0]
document.seldom.value=totals[1]
document.often.value=total[2]
document.always.value=totals[3]

Nothing happens when I test this form, no numbers appear anywhere.

Is this coding useless in some fashion?
Is there some simple thing I've missed out on because I've looked at it for so long?

I'd be most grateful if someone would stop me from scratching my head any more.....

head8k
02-14-2003, 02:06 PM
There was too much wrong with your example that I pretty much started from scratch. The attached file should give you an idea of how to do it.

I hope this is what you are looking for.

:thumbsup: