This topic is locked
[SOLVED]

 javascript on load on the fly calculations

9/21/2012 4:20:16 PM
PHPRunner General questions
C
ckapote author

hi i have following
var ctrltotalvolumeweight = Runner.getControl(pageid, 'totalvolumeweight');
var ctrlwidth = Runner.getControl(pageid, 'width');
var ctrlheight = Runner.getControl(pageid, 'height');
var ctrllength = Runner.getControl(pageid, 'length');
function func() {
ctrltotalvolumeweight.setValue(Number((ctrlwidth.getValue()) Number(ctrlheight.getValue()) Number(ctrllength.getValue())/6));
};
ctrlwidth.on('keyup', func);
ctrlheight.on('keyup', func);
ctrllength.on('keyup', func);
inspired by

http://xlinesoft.com/phprunner/docs/how_to_calculate_values_on_the_fly.htm
i need to get on the fly the total of totalvolumeweight is it that possible ?
thanks

chris

C
cgphp 9/21/2012

What error do you get in firebug?

C
ckapote author 9/22/2012

I am not getting any error the code above is working and getting the result i need on totalvolumeweight field.
I need in additional to get a sum of totalvolumeweight on the fly at the bottom .
can you help?



What error do you get in firebug?

C
cgphp 9/22/2012

In the code above you are just calculating the totalvolumeweight.

C
ckapote author 9/22/2012

cORRECT and that code working very good .
I need to add a code to row sum totalvolumeweight
can you help ?



In the code above you are just calculating the totalvolumeweight.

C
cgphp 9/22/2012

What does "to row sum totalvolumeweight" mean?

C
ckapote author 9/22/2012

ok i am sorry if that was not clear .
what i need is to generate on the fly the totalvolumeweight sum for example i have below the table i use with the code i have add at the beginning of conversation:
height x width x length= totalvolumeweight
2 x 2 x 2 = 8 ( i get that on the fly)

3 x 3 x 3 = 27 ( i get that on the fly)

2 x 1 x 1 = 2 ( i get that on the fly)
i need to get on the fly the sum of totalvolumeweight i.e. 8+27+2= 47 ( i need the code to get that sum on the fly as i get the height width length on the fly )
can you please help ?



What does "to row sum totalvolumeweight" mean?

C
cgphp 9/23/2012

Get control of each field. If you have three width fields, the code will be:

var ctrlwidth1 = Runner.getControl(pageid, 'width1');

var ctrlwidth2 = Runner.getControl(pageid, 'width2');

var ctrlwidth3 = Runner.getControl(pageid, 'width3');


Replace width1, width2 and width3 with the real names of width fields. Do the same thing for the totalvolumeweight field, the height field and the length field.

C
ckapote author 9/23/2012

very good idea Cristian thanks for the tip.
Can i ask one more?
lets say i get on the fly the sum of width1+width2+width3 which is for example 40

and also i get on the fly the sum of height1+height2+height3 which is for example 60

Now I have a field called actualvolume which the value of that field on the fly is the larger sum from above two calculations i.e. actualvolume = 60 ( which on that example is the sum of height)
i mean i need the java script to check if sum of width is larger than the sum of height and to get on the fly the value on actualvolume field or if the

sum of height is larger than the sum of width to get that value on the fly on actualvolume field.
thanks in advance

chris



Get control of each field. If you have three width fields, the code will be:

var ctrlwidth1 = Runner.getControl(pageid, 'width1');

var ctrlwidth2 = Runner.getControl(pageid, 'width2');

var ctrlwidth3 = Runner.getControl(pageid, 'width3');


Replace width1, width2 and width3 with the real names of width fields. Do the same thing for the totalvolumeweight field, the height field and the length field.