Online calculator in Javascript

Dear All,

My request is connected to this discussion : https://www.sawtoothsoftware.com/forum/1474/need-script-constant-sum-total-free-form-numeric-entry-list?show=1474#q1474

I have created an online calculator (free format) to show respondents savings they can do on a product. Product got some variables which can be modified according to needs. In the calculator there are 8 rows , first five can be modified and last 3 give results based on these 5 rows.
Variables and formulas are as below :
r1
r2
r3
r4
r5
r6=r5*r1/r2+r1
r7=r6-r1
r8=r7*r4*r3

Im able to make working in javascript formula for r6 but I got stuck on r7 as it uses same variable
for r6 and r7 => I mean 'r1'.
So the HTML <Head> Tag is as below :


<script type="text/javascript">

function calcR6()
{
var r6 = 0;
r6 = (Number(document.getElementById("Throughput_r5").value)
* Number(document.getElementById("Throughput_r1").value)
/ Number(document.getElementById("Throughput_r2").value))
+ Number(document.getElementById("Throughput_r1").value)
;
document.getElementById("Throughput_r6").value = r6;
}

function calcR7()
{
var r7= 0;
r7 = Number(document.getElementById("Throughput_r6").value)
- Number(document.getElementById("Throughput_r1").value);
document.getElementById("Throughput_r7").value = r7;
}


function calcR8()
{
var r8 = 0;
r8 = Number(document.getElementById("Throughput_r7").value)
* Number(document.getElementById("Throughput_r4").value)
* Number(document.getElementById("Throughput_r3").value)
;
document.getElementById("Throughput_r8").value = r8;
}


</script>


and the grid setup for r1
<td style="text-align: left;"> <input name="Throughput_r1" id="Throughput_r1" type="text" size="3" onChange="calcR6()" > </td>

the issue is that r1 I would need to pipe in to calcR6() and calcR7() functions... something like :
<td style="text-align: left;"> <input name="Throughput_r1" id="Throughput_r1" type="text" size="3" onChange="calcR6()" onChange="calcR7()" > </td>

but obviously it doesn't work....
I would be very grateful for any ideas .....

robson

Resolved
2 replies