maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

How to add two fields and display in text area?

Please post UI screen shots, and the exact code that you use.

Ryan Bloom
Posts: 0
Joined: Tue Feb 12, 2013 6:24 pm

How to add two fields and display in text area?

the code is shown in the screenshot

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

How to add two fields and display in text area?

Hello! Try this code

codevar ap = Tiggzi('AP').val(),
mp = Tiggzi('MP').val();

if (ap.charAt(0) === "$") {
ap = ap.slice(1);
}
if (mp.charAt(0) === "$") {
mp = mp.slice(1);
}

var apNumber = parseFloat(ap),
mpNumber = parseFloat(mp);
Tiggzi('TotalCost').val("$" + (apNumber + mpNumber));/code

Ryan Bloom
Posts: 0
Joined: Tue Feb 12, 2013 6:24 pm

How to add two fields and display in text area?

It worked!! Thank you so much!

Ryan Bloom
Posts: 0
Joined: Tue Feb 12, 2013 6:24 pm

How to add two fields and display in text area?

Marina,

I have one more question: would it be possible to take the total of that calculation and divide it by the input "Years" which is the number of years in the screenshot?

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

How to add two fields and display in text area?

codefunction isNumeric(n) {
return !isNaN(parseFloat(n)) && isFinite(n);
}

var ap = Tiggzi('AP').val(),
mp = Tiggzi('MP').val(),
years = Tiggzi('Years').val();

if (ap.charAt(0) === "$") {
ap = ap.slice(1);
}
if (mp.charAt(0) === "$") {
mp = mp.slice(1);
}

var apNumber = parseFloat(ap),
mpNumber = parseFloat(mp),
yearsNumber = parseFloat(years),
total, result;
total = (apNumber + mpNumber)/yearsNumber;

if (isNumeric(total)) {
result = total.toFixed(2); //show 2 digits after "dot"
} else {
result = 0; //default value (if some fields incorrect)
}

Tiggzi('TotalCost').val("$" + result);/code

in line years = Tiggzi('Years').val();

Years is your component name

Ryan Bloom
Posts: 0
Joined: Tue Feb 12, 2013 6:24 pm

How to add two fields and display in text area?

That worked beautifully! If I want to take that result and divide by 173 how would I do that? I tried to change the equation and have it display the result in textarea "HourlyCost" but it would not work. Thank you again!

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

How to add two fields and display in text area?

Please add next lines

codevar HourlyCost = total/173,
resultHourlyCost;
if (isNumeric(HourlyCost)) {
resultHourlyCost = HourlyCost.toFixed(2); //show 2 digits after "dot"
} else {
resultHourlyCost = "0&quot //default value (if some fields incorrect)
}

Tiggzi('HourlyCost').val("$" + resultHourlyCost);/code

Ryan Bloom
Posts: 0
Joined: Tue Feb 12, 2013 6:24 pm

How to add two fields and display in text area?

Thank you very much Marina, you have been very helpful.

Return to “Issues”