Search code examples
javascriptadobeacrobat

I cant for the life of me figure out whats wrong with this script


var cb1 = this.getField("Check Box1").isBoxChecked(0); 
var cb2 = this.getField("Check Box3").isBoxChecked(0); 
var cb3 = this.getField("Check Box4").isBoxChecked(0); 
var cb4 = this.getField("Check Box5").isBoxChecked(0); 
var cb5 = this.getField("Check Box6").isBoxChecked(0); 
var cb6 = this.getField("Check Box7").isBoxChecked(0); 
var cb7 = this.getField("Check Box8").isBoxChecked(0); 

if (cb1 && cb2 && cb3 && cb4 && cb5 && cb6 && cb7)
{ event.value = "0"; } 

let totalDays = this.getField("Totaldays").value;
[
{checked: cb1, rentalRate: 0}, {checked: cb2, rentalRate: 30}, {checked: 
cb3, rentalRate: 20}, {checked: cb4, rentalRate: 0}, {checked: cb5, 
rentalRate: 40}, {checked: cb6, rentalRate: 0}, {checked: cb7, rentalRate: 
0} 
]
.filter(item => item.checked) .forEach(item => { let rentalFee = 
item.rentalRate * totalDays; event.value += rentalFee; });

It keeps stating there is a "syntax error: Missing ; before statement." Does anyone see anything obvious that I am just missing? I feel like I need a fresh set of eyes to look it over. I am working in Adobe Acrobat DC fyi. In the image, I drew an arrow to wear it highlights and mentions the arrow. Thank you in advance!

Syntax Error


Solution

  • Pay attention that for now Adobe Acrobat DC seems to use javascript version 1.5 (ECMA-262 3rd edition) which does not implement features that you use.

    You should first try to replace your arrow functions (introduced in ECMA-262 6th edition):

    .filter(function (item) {
      return item.checked;
    }).forEach(function (item) {
      var rentalFee = item.rentalRate * totalDays;event.value += rentalFee;
    });