How to add two fields and display in text area?
Please post UI screen shots, and the exact code that you use.
Catch up wih the Appery.io community on our forum. Here you'll find information on the lastest questions and issues Appery.io developers are discussing.
https://forum.appery.io/
Please post UI screen shots, and the exact code that you use.
the code is shown in the screenshot
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
It worked!! Thank you so much!
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?
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
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!
Please add next lines
codevar HourlyCost = total/173,
resultHourlyCost;
if (isNumeric(HourlyCost)) {
resultHourlyCost = HourlyCost.toFixed(2); //show 2 digits after "dot"
} else {
resultHourlyCost = "0" //default value (if some fields incorrect)
}
Tiggzi('HourlyCost').val("$" + resultHourlyCost);/code
Thank you very much Marina, you have been very helpful.