Copy link to clipboard
Copied
I have made a form with the purpose of having multiple dropdowns for inserting an 'ID number' which would then populate the following text fields: 'description,' & 'total'
The problem I am having the calculations in SetTotalValues:
TypeError: (intermediate value).find is not a function 240:Document-Level:SetFieldValues
var DeptData = {
0:{
description: "SUBTOTAL",
description2: "20% BUILDERS MARGIN",
description3: "SUBTOTAL W/ MARGIN",
description4: "QBCC Home Warranty Insurance",
description5: "TOTAL",
description6: "GST",
description7: "TOTAL W/ GST",
description8: "******************************************************************************************************************" ,
quantity: "",
unit: "",
price: ""
},
};
function SetTotalValues(cID, idx) {
this.getField("Desc"+(parseInt(idx))).value = DeptData[cID].description;
this.getField("Desc"+(parseInt(idx)+1)).value = DeptData[cID].description2;
this.getField("Desc"+(parseInt(idx)+2)).value = DeptData[cID].description3;
this.getField("Desc"+(parseInt(idx)+3)).value = DeptData[cID].description4;
this.getField("Desc"+(parseInt(idx)+4)).value = DeptData[cID].description5;
this.getField("Desc"+(parseInt(idx)+5)).value = DeptData[cID].description6;
this.getField("Desc"+(parseInt(idx)+6)).value = DeptData[cID].description7;
this.getField("Desc"+(parseInt(idx)+7)).value = DeptData[cID].description8;
this.getField("Total"+(parseInt(idx))).value = "122";;
this.getField("Total"+(parseInt(idx)+1)).value = 0.2 * this.getField("Total"+(parseInt(idx))).value;
this.getField("Total"+(parseInt(idx)+2)).value = this.getField("Total"+(parseInt(idx))).value + this.getField("Total"+(parseInt(idx)+1)).value;
this.getField("Total"+(parseInt(idx)+3)).value = ([(this.getField("Desc"+(parseInt(idx)+3)).value)].map(getValue));
this.getField("Total"+(parseInt(idx)+4)).value = this.getField("Total"+(parseInt(idx)+2)).value + this.getField("Total"+(parseInt(idx)+3)).value;
this.getField("Total"+(parseInt(idx)+5)).value = 0.1 * this.getField("Total"+(parseInt(idx)+4)).value;
this.getField("Total"+(parseInt(idx)+6)).value = this.getField("Total"+(parseInt(idx)+4)).value + this.getField("Total"+(parseInt(idx)+5)).value;
this.getField("Total"+(parseInt(idx)+7)).value = "*****";
}
Why don't the calculations work?
Any help is much appreciated!!!
find: run a loop on the array and return the first item that satisfies the desired condition.
map: run a loop on the array, processing all items in the desired way.
You can create your own functions that will do it and just call them with the array as a parameter.
Copy link to clipboard
Copied
Why does you use the following:
this.getField("Total"+(parseInt(idx)+3)).value = ([(this.getField("Desc"+(parseInt(idx)+3)).value)].map(getValue));
Copy link to clipboard
Copied
@Bernd Alheit
Sorry, I left out another variable :
var getValue = total => [ [3300, 194.25], [4000, 197.5], [237000, 1281.65], [238000, 1286.3], [Infinity, 999999], ].find(([t]) => total <= t)[1];
I can't even make this script work by itself though:
this.getField("Total"+(parseInt(idx))).value = "122";
Thanks for your reply Bernd!
Copy link to clipboard
Copied
Any error?
Copy link to clipboard
Copied
@Bernd Alheit
Yes, still not working! 😞
This code wont work even alone:
this.getField("Total"+(parseInt(idx))).value = "122";
Copy link to clipboard
Copied
What is the value of idx?
Copy link to clipboard
Copied
I recommend not using these functions (find, map, etc.) in your code. They were only added to latest versions of Acrobat (and Reader) DC, and will not work in earlier versions. Stick to the code JavaScript functions and it will work every time.
Copy link to clipboard
Copied
@try67
What would be the alternative to find and map?
Thanks for your help!
Copy link to clipboard
Copied
find: run a loop on the array and return the first item that satisfies the desired condition.
map: run a loop on the array, processing all items in the desired way.
You can create your own functions that will do it and just call them with the array as a parameter.