Calculate 2 boxes

This forum contains topics that were moved from Get Satisfaction
Mark7294305
Posts: 0
Joined: Fri Dec 26, 2014 2:10 am

Calculate 2 boxes

Post by Mark7294305 »

Hello Support
I have an App where I wish to add the totals of two input boxes together. For example in Box A I receive prices from an Api which go into this box. Box B contains the current balance. I wish for Box C to equal Box A + Box B,

How do I do this?

She
Posts: 0
Joined: Wed Oct 08, 2014 12:46 am

Calculate 2 boxes

Post by She »

Hi mark,

for example you have 2 textInput and name it A,B,

var a = parseInt(Appery("a").val());
var b = parseInt(Appery("b").val());
alert(a+b);

Mark7294305
Posts: 0
Joined: Fri Dec 26, 2014 2:10 am

Calculate 2 boxes

Post by Mark7294305 »

Hi
How do I make the results of A + C appear in box C?

She
Posts: 0
Joined: Wed Oct 08, 2014 12:46 am

Calculate 2 boxes

Post by She »

hi mark
i hope this link may help you out your problem.

http://stackoverflow.com/questions/16...

Mark7294305
Posts: 0
Joined: Fri Dec 26, 2014 2:10 am

Calculate 2 boxes

Post by Mark7294305 »

Hi Support
Thanks for your reply.

I actually found the solution on the Tip calculator youtube vid and tweaked it as follows

var Box_A = Number(Apperyio("Box_A").val());
var Box_B = Number(Apperyio("Box_B").val());

var Box_C = Box_A + Box_B;

Apperyio('Box_C').text(Box_C.toFixed(2));
//Apperyio('Box_C').text('£' + Box_C.toFixed(2));

this works but the problem I now have is as I mentioned before I receive prices into Box A from a 3rd API. The results are received and displayed as "£3.50" for example into Box A. When adding Box A and Box B, Box C displays "NaN". If I then manually delete the "£" out of Box A it works fine. So the "£" is causing the "NAN" problem. How can I configure it to ignore the "£" and just add the "3.50"?

Egor Kotov6832188
Posts: 0
Joined: Wed Nov 19, 2014 5:15 pm

Calculate 2 boxes

Post by Egor Kotov6832188 »

Hello Mark,

Please use
parseFloat(Apperyio("Box_A").val());
instead of
Number(Apperyio("Box_A").val());

Note: same for Box_b

Post Reply