I'm trying to create a form with:
This is the only calculation in the form, so changing the calculation order is not used. In the document javascript, I have
this.calculateNow();
and in the custom calculation script for the field, I have
(function () {
var v1 = +getField("Text1").value;
var v2 = +getField("Text2").value;
var v3 = +getField("Text3").value;
var v4 = +getField("Text4").value;
var v5 = +getField("Text5").value;
var v6 = +getField("Text6").value;
var v7 = +getField("Text7").value;
var v8 = +getField("Text8").value;
var v9 = +getField("Text9").value;
var v10 = +getField("Text10").value;
event.value = (v2 * v4 * v6 * v8 * v10) !== 0 ? ((v1 * v3 * v5 * v7 * v9) / (v2 * v4 * v6 * v8 * v10)) : "";
})();
The issues I'm having:
Your code is a bit repetitive. You may use an array containing the field ids:
const fields = Array.from({length:10}, (_,i)=>"Text"+(i+1));
Then we can map the fields to their value and use the or operator to fill unset fields:
const values = fields.map( f => +getField(f).value || 1 );
That array then can be reduced to a certain value, eg with mutliplication:
const result = values.reduce((a,b) => a*b)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.