Copy link to clipboard
Copied
I created a PDF form and need some help with the custom script to autopopulat a field with a number based on a drop-down field and one of two other fields.
In the above image, a number (1-10) is selected in the Family Of drop-down field. Then a dollar amount is entered into either Monthly Adjusted Gross or Biweekly Adjusted Gross. The number in Family Of field
determines what range of numbers to look at along with the number entered in the Monthly or Biweekly field to then determine what the Monthly Fee field number will be.
For example:
If Family Of is 1, Monthly Gross is 3000, then based on the Family of 1 income data:
The Monthly Fee field will then autopopulate with 10. The tricky part is because the range of numbers changes based on the Family Of number. And we may have a number in the Monthly or the Biweekly field, so it would need to look at whichever field has a number entered into it.
I've tried various custom calculation scripts from other posts, but none of them have worked. The fields are simply named Family Of, Monthly, Biweekly, and Fee to make my life easier. Any help with this would be greatly appreciated!!!
Copy link to clipboard
Copied
So you just need fee based on monthly or weekly, you don't need dropdown in calculation?
Try this:
var ranges = [
{ min: 2511, max: 3031, fee: 10 },
{ min: 3032, max: 3551, fee: 18 },
{ min: 3552, max: 4071, fee: 27 }
];
var month = Number(this.getField("Monthly").valueAsString);
var week = Number(this.getField("Biweekly").valueAsString);
var fee = 0;
for(var i=0; i<ranges.length; i++) {
if (month != 0) {
if (month >= ranges[i].min && month <= ranges[i].max) {
fee = ranges[i].fee;
break;}}
else if (week != 0) {
if (week >= ranges[i].min && week <= ranges[i].max) {
fee = ranges[i].fee;
break;}}}
event.value = fee;