Page 2 of 3

How to add two fields and display in text area?

Posted: Thu Feb 14, 2013 6:27 am
by maxkatz

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


How to add two fields and display in text area?

Posted: Thu Feb 14, 2013 6:46 am
by Ryan Bloom

How to add two fields and display in text area?

Posted: Thu Feb 14, 2013 6:47 am
by Ryan Bloom

the code is shown in the screenshot


How to add two fields and display in text area?

Posted: Thu Feb 14, 2013 7:19 am
by Maryna Brodina

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


How to add two fields and display in text area?

Posted: Thu Feb 14, 2013 7:23 am
by Ryan Bloom

It worked!! Thank you so much!


How to add two fields and display in text area?

Posted: Thu Feb 14, 2013 7:35 am
by Ryan Bloom

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?


How to add two fields and display in text area?

Posted: Thu Feb 14, 2013 8:48 am
by Maryna Brodina

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


How to add two fields and display in text area?

Posted: Thu Feb 14, 2013 2:39 pm
by Ryan Bloom

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!


How to add two fields and display in text area?

Posted: Thu Feb 14, 2013 3:08 pm
by Maryna Brodina

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


How to add two fields and display in text area?

Posted: Thu Feb 14, 2013 7:00 pm
by Ryan Bloom

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