This topic is locked

calculate SUB on the fly

11/22/2011 11:04:07 AM
PHPRunner General questions
S
seeunextweek124 author

hi,
i am wondering myself about how to create a custom JavaScript Onload event (to calculate on the fly) that does the following:

i have 3 fields - car, autobahns, othervehicles. Now i want to create a function that gets the Sum of all 3 fields on the fly?

For example $car=4; $autobahns=2; and $othervehicles=4 and the Sum of all would be Sum=$car+$autobahns+$othervehicles=10 ?
Can anyone please help me how to make that function work on PHPRunner 5.2 / PHPRunner 6.0?

Is there a way to combine two or more functions in one?

The function should work on add/edit pages if possible.
p.s. i have searched the forum about that but could not find any equal examples. [[ PHPRunner ]]
Thanks. <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=question&id=18394&image=1&table=forumtopics' class='bbc_emoticon' alt=':huh:' /> <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=question&id=18394&image=2&table=forumtopics' class='bbc_emoticon' alt=':rolleyes:' />

S
seeunextweek124 author 11/22/2011

Hi,
thank you : Cristian Gilè , but i forgot to mention that i checked the manual(the on-line one the one that comes with the app ) and the in the forum too.

Isn't it possible to give me an answer to my question? and is there a way to combine two or more functions ??
Thanks.

C
cgphp 11/23/2011

What do you mean for "combine" ?

S
seeunextweek124 author 11/23/2011

combine=> join into one function only.
can you(Cristian Gilè) help me with creating that function please?
thanks.

C
cgphp 11/23/2011
var ctrlCar = Runner.getControl(pageid,'car')

var ctrlAuto = Runner.getControl(pageid,'autobahns');

var ctrlOther = Runner.getControl(pageid,'othervehicles');

var ctrlSum = Runner.getControl(pageid,'Sum');
var ctrlCar_value = parseInt(ctrlCar.getValue());

var ctrlAuto_value = parseInt(ctrlAuto.getValue());

var ctrlOther_value = parseInt(ctrlOther.getValue());
function sum_values(p1,p2,p3)

{

var sum = 0;

sum = p1 + p2 + p3;

ctrlSum.setValue(sum);

}
ctrlCar.on('change', sum_values(ctrlCar_value, ctrlAuto_value, ctrlOther_value));

ctrlAuto.on('change', sum_values(ctrlCar_value, ctrlAuto_value, ctrlOther_value));

ctrlOther.on('change', sum_values(ctrlCar_value, ctrlAuto_value, ctrlOther_value));
S
seeunextweek124 author 12/2/2011


var ctrlCar = Runner.getControl(pageid,'car')

var ctrlAuto = Runner.getControl(pageid,'autobahns');

var ctrlOther = Runner.getControl(pageid,'othervehicles');

var ctrlSum = Runner.getControl(pageid,'Sum');
var ctrlCar_value = parseInt(ctrlCar.getValue());

var ctrlAuto_value = parseInt(ctrlAuto.getValue());

var ctrlOther_value = parseInt(ctrlOther.getValue());
function sum_values(p1,p2,p3)

{

var sum = 0;

sum = p1 + p2 + p3;

ctrlSum.setValue(sum);

}
ctrlCar.on('change', sum_values(ctrlCar_value, ctrlAuto_value, ctrlOther_value));

ctrlAuto.on('change', sum_values(ctrlCar_value, ctrlAuto_value, ctrlOther_value));

ctrlOther.on('change', sum_values(ctrlCar_value, ctrlAuto_value, ctrlOther_value));



Thanks you saved me.