最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to use If else statements in PDF javascript - Stack Overflow

programmeradmin1浏览0评论

I am looking to have a PDF calculate an answer based on the inputs from multiple fields and dropdowns.

I am using input fields for No. of Units, Oil Cost, Oil Changes per Week and a dropdown for Single Fryer which when all inputted will hopefully calculate a per annum cost for oil usage in a fryer.

The code I am trying to us is below;

I would expect with the below units inputted into their associated fields an answer of 62,400,


if ((this.getField("Single Fryer").value) = "MJ150") {
    event.value = (this.getField("No. of Units").value) * (this.getField("Oil Cost").value) * (this.getField("Oil Changes per Week").value) * 25 * 52
} else if ((this.getField("Single Fryer").value) = "MJ140" {
    event.value = (this.getField("No. of Units").value) * (this.getField("Oil Cost").value) * (this.getField("Oil Changes per Week").value) * 20 * 52
} else if ((this.getField("Single Fryer").value) = "SR42" {
    event.value = (this.getField("No. of Units").value) * (this.getField("Oil Cost").value) * (this.getField("Oil Changes per Week").value) * 20 * 52
} else if ((this.getField("Single Fryer").value) = "RE114" {
    event.value = (this.getField("No. of Units").value) * (this.getField("Oil Cost").value) * (this.getField("Oil Changes per Week").value) * 20 * 52
} else if ((this.getField("Single Fryer").value) = "RE117" {
    event.value = (this.getField("No. of Units").value) * (this.getField("Oil Cost").value) * (this.getField("Oil Changes per Week").value) * 20 * 52
} else {
    event.value = "N/A"
}

  1. No. of Units = 4
  2. Oil Cost ($/L) = 4
  3. Oil Changes per Week = 3
  4. Single Fryer = MJ150

However I am getting the below syntax error when trying to input the code;

SyntaxError: Missing ) after condition 3: at line 4

Am using Adobe Acrobat X if that makes a difference.

This is my first time using Javascript so any help/recommendations would be appreciated.

I am looking to have a PDF calculate an answer based on the inputs from multiple fields and dropdowns.

I am using input fields for No. of Units, Oil Cost, Oil Changes per Week and a dropdown for Single Fryer which when all inputted will hopefully calculate a per annum cost for oil usage in a fryer.

The code I am trying to us is below;

I would expect with the below units inputted into their associated fields an answer of 62,400,


if ((this.getField("Single Fryer").value) = "MJ150") {
    event.value = (this.getField("No. of Units").value) * (this.getField("Oil Cost").value) * (this.getField("Oil Changes per Week").value) * 25 * 52
} else if ((this.getField("Single Fryer").value) = "MJ140" {
    event.value = (this.getField("No. of Units").value) * (this.getField("Oil Cost").value) * (this.getField("Oil Changes per Week").value) * 20 * 52
} else if ((this.getField("Single Fryer").value) = "SR42" {
    event.value = (this.getField("No. of Units").value) * (this.getField("Oil Cost").value) * (this.getField("Oil Changes per Week").value) * 20 * 52
} else if ((this.getField("Single Fryer").value) = "RE114" {
    event.value = (this.getField("No. of Units").value) * (this.getField("Oil Cost").value) * (this.getField("Oil Changes per Week").value) * 20 * 52
} else if ((this.getField("Single Fryer").value) = "RE117" {
    event.value = (this.getField("No. of Units").value) * (this.getField("Oil Cost").value) * (this.getField("Oil Changes per Week").value) * 20 * 52
} else {
    event.value = "N/A"
}

  1. No. of Units = 4
  2. Oil Cost ($/L) = 4
  3. Oil Changes per Week = 3
  4. Single Fryer = MJ150

However I am getting the below syntax error when trying to input the code;

SyntaxError: Missing ) after condition 3: at line 4

Am using Adobe Acrobat X if that makes a difference.

This is my first time using Javascript so any help/recommendations would be appreciated.

Share Improve this question asked 13 hours ago SupOnlySupOnly 111 bronze badge New contributor SupOnly is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct. 5
  • to see why YOUR code fails it helps to see the pdf that has the fields and values even if it is a minimal few otherwise dozens of people will need to duplicate your one file and not get it the same. link to a PDF via clean service such as easyupload.io/#how-it-works – K J Commented 13 hours ago
  • HERE test the simple js in this mock-up of your PDF easyupload.io/izztqf – K J Commented 10 hours ago
  • If this is regular JS then each comparison should use === or if that is somehow not supported then it should use ==: if ((this.getField("Single Fryer").value) === "MJ150") – Peter B Commented 7 hours ago
  • @PeterB in Adobe the single = when used for compare will be the Adobe use of doubles == as shown in my working example. and if you reflow the logic will only be needed once for the 25 litre Drum. – K J Commented 6 hours ago
  • World: we want standards! Adobe: hold my beer
发布评论

评论列表(0)

  1. 暂无评论