tburger
01-18-2012, 03:40 PM
Folks,
I am trying to calculate the total of fields on a web form.
I have multiple rows of 10 fields with a total for each.
Each row comes from a different record in a database.
I am only showing 2 fields of the 10 for simplicity.
The name and id of each field looks like
"Q300_1" onchange="update(Q300)"
"Q300_2" onchange="update(Q300)"
"Q300_t"
"Q301_1" onchange="update(Q301)"
"Q301_2" onchange="update(Q301)"
"Q301_t"
My current attempt at the script looks like:
[CODE]
<script type="text/javascript">
function update(item) {
var itemt=item + "_t";
var item1=item + "_1";
var item2=item + "_2";
document.myform[itemt].value = (document.myform[item1].value -0) + (document.myform[item2].value -0);
}
</script>
[CODE]
It does not work and I get
Error: Q301 is not defined
in the Firefox error console.
I am trying to calculate the total of fields on a web form.
I have multiple rows of 10 fields with a total for each.
Each row comes from a different record in a database.
I am only showing 2 fields of the 10 for simplicity.
The name and id of each field looks like
"Q300_1" onchange="update(Q300)"
"Q300_2" onchange="update(Q300)"
"Q300_t"
"Q301_1" onchange="update(Q301)"
"Q301_2" onchange="update(Q301)"
"Q301_t"
My current attempt at the script looks like:
[CODE]
<script type="text/javascript">
function update(item) {
var itemt=item + "_t";
var item1=item + "_1";
var item2=item + "_2";
document.myform[itemt].value = (document.myform[item1].value -0) + (document.myform[item2].value -0);
}
</script>
[CODE]
It does not work and I get
Error: Q301 is not defined
in the Firefox error console.