LoreleiBunjes1
5 years agoQrew Member
Save javascript generated value to a field
Hi
Long story short but my team uses decimals to track a length, but we need to send reports to an external vendor that has the length formatted as a fraction. Example:
Field (Numeric) "Internal Length in Inches": 6.625
Field (Text) "Vendor Length in Inches - Helper": 6-5/8
I haven't been able to find a GCD function in Quick Base that I can use for a formula but I did come up with a javascript in a rich text formula field that converts the decimal into the formatted fraction (below).
Now I need to be able to save the returned JS value as text in a "Vendor Length in Inches" (text) field.
I've tried:
Thank you
------------------------------
Lorelei B
------------------------------
Long story short but my team uses decimals to track a length, but we need to send reports to an external vendor that has the length formatted as a fraction. Example:
Field (Numeric) "Internal Length in Inches": 6.625
Field (Text) "Vendor Length in Inches - Helper": 6-5/8
I haven't been able to find a GCD function in Quick Base that I can use for a formula but I did come up with a javascript in a rich text formula field that converts the decimal into the formatted fraction (below).
Now I need to be able to save the returned JS value as text in a "Vendor Length in Inches" (text) field.
I've tried:
- Injecting the returned value into the form field via javascript but it doesn't save the value, just blank.
- Using a field formula to grab the helper field, but that only saves the script code.
Thank you
"<img src onerror='
this.outerHTML=(
function(x) {
var decimal = x;
var decimal_string = decimal.toString();
var decimal_array = decimal_string.split(".");
var whole_number = parseInt(decimal_array[0]);
var numerator = parseInt(decimal_array[1]);
var fraction_power = numerator.toString().length;
var denominator = Math.pow(10, fraction_power);
var gcd;
var a = numerator;
var b = denominator;
while (a!=b){
if (a>b){
a = a -b;
} else {
b = b - a;
}
}
gcd = a;
var vendor_length = whole_number+"-"+numerator/gcd+"/"+denominator/gcd;
document.getElementById("_fid_9").value=vendor_length;
return vendor_length;
}
)
(" & [Internal Length] & ");
'>"
------------------------------
Lorelei B
------------------------------