Hi all,
how can we use dynamic calculation(EX:: if i enter value 1 in field1 and 2 in field2 then it should sum both number and display 3 in fieldd 3,i know that we can use formula fields but we need to see the result before saving the record.i.e Dynamic calculation field).
any one pls help me how can i do the above.
Hi Sudhakar,
You can use Rollbase client-side APIs to compute the total dynamically.
For example, you have 'num1', 'num2', 'num3' and 'sumField' integer fields on your form. To compute the sum, paste the code below on a script component on your form's page editor:
<script>
function computeSum() {
var num1 = rbf_getFieldValue('num1'),
num2 = rbf_getFieldValue('num2'),
num3 = rbf_getFieldValue('num3'),
sum = parseInt(num1) + parseInt(num2) + parseInt(num3);
rbf_setFieldValue('sumField', sum);
}
</script>
Then, add the computeSum() function to the onchange events of 'num1', 'num2' and 'num3' fields. This will compute for the total when any of the three fields are changed.
Please see Chapter 7 of Rollbase in Action.
Regards,
Godfrey
Hello,
I tried this one but i am not able to get the output.
Here is the CODE.
<script>
function computeSum() {
var num1 = rbf_getFieldValue('interest_rate'),
num2 = rbf_getFieldValue('term'),
num3 = rbf_getFieldValue("amount'),
var rate = num1/(100*12);
var r = rate + 1;
var calc = 1-(Math.pow(r, - num2));
var p = (rate/calc) * num3;
p = p.toFixed(2);
if (p == "Infinity" || p == "NaN") return 0;
else {
rbf_setFieldValue('payment',p);}
}
</script>
NOTE:
1. interest_rate is percentage field.
2. term is radio button field.
3. amount is Currency field.
Please check it and Help to solve this.
Thanks
Jigs Mehta
Hi Jigs,
I've noticed a few errors from from your code. Please see my comments below:
Kindly also post the error message from the console ,if any, so I can assist you more effectively on this issue.
Regards,
Godfrey