Hello @tilou,
The easiest way to use this equation, assuming that X, and Y are the fields: fieldname1 and fieldname2 respectively (you should use the real fields names in your form), the equation to associate with the calculated field would be as simple as:
(function(){
function ratio(x,y) {c=gcd(x,y); return ""+(x/c)+":"+(y/c)};
return ratio(fieldname1,fieldname2);
})()
and that’s all.
Best regards.
Thread Starter
tilou
(@tilou)
Great thanks! It works!
Hope am not abusing your time can you please help me with this one?
function gcd(a,b) {if(b>a) {temp = a; a = b; b = temp} while(b!=0) {m=a%b; a=b; b=m;} return a;}
-
This reply was modified 8 years, 3 months ago by
tilou.
Hello @tilou,
I don’t understand what do you need, because the solution is just the same. Even if you want create your functions globally, to use them from multiple equations, you simply should insert a “HTML Content” field in the form with the following piece of code as its content:
<script>
window['gcd'] = function(a,b) {if(b>a) {var temp = a; a = b; b = temp} while(b!=0) {var m=a%b; a=b; b=m;} return a;};
window['ratio'] = function (x,y) {var c=gcd(x,y); return ""+(x/c)+":"+(y/c)};
</script>
Now, to use this operations in the equations is as simple as:
ratio(fieldname1,fieldname2)
or
gcd(fieldname5,fieldname9)
I’m sorry, but the support service does not covers the implementation of the users projects (forms or formulas). If you need additional help implementing your project, I can offer you a custom coding service from my private website:
https://cff.dwbooster.com/customization
Best regards.