Hi there,

I've been searching the web for some time to find a way to calculate the values of a number of input fields. I found that one has to use parseint() to get a numerical value and then you can just add each value.

Now I would like to create a function that can do this automaticaly for each input field with a certain name. But I just can't seem to get it right.

My form looks like this, for example:

Code:

<form name="form">
<p>Question A1</p>
<input type="text" name="A1[]" /><br />
<input type="text" name="A1[]" /><br />
<input type="text" name="A1[]" /><br />
<p>Question A2</p>
<input type="text" name="A2[]" /><br />
<input type="text" name="A2[]" /><br />
<input type="text" name="A2[]" /><br />
</form>

Now I would like to sum all the values of the input fields named A1 or A2 using a function:

Code:

// Not working by the way ....
function Sum(name) {
for(i = 0; i < document.form.name.value.lenght; i++) {
sum = parseint( ... something here ...);
}
return sum;
}

I quess the function has to look something like this, but it doesn't quite works. The problem is that I don not have enough experience with javascript to get the object right.

I hope someone can help me out with this, or at least give me some tips on which I can get a bit further ...

Thanks in advance,

Michiel