• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
16

Populating values when a checkbox selected and data is in a field

Explorer ,
Nov 27, 2023 Nov 27, 2023

Copy link to clipboard

Copied

I'm making a form for my organization and I want to assign a dollar amount to a field. The dollar amount is based off of the complexity (value ranges between 1 and 10) and if the access control is yes or a no (Access control yes is an interstate project and no access control is a highway project). Can someone give me an example of a custom script for this?

Badhawg66_0-1701117107649.png

Badhawg66_1-1701117134127.png

Badhawg66_2-1701117149242.png

TOPICS
How to , JavaScript , PDF , PDF forms

Views

570

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Nov 28, 2023 Nov 28, 2023

You can use this script as 'Custom calculation script', you can put it in "Text1" field.

Just finish list with all the prices.

var cpx = Number(this.getField("Complexity").valueAsString);
var chk = this.getField("Check Box").valueAsString;
var total1 = 0;
var total2 = 0;
var prices = [
{complexity: 1, check: "Yes", price1: 459, price2: 966 },
{complexity: 1, check: "No",  price1: 364, price2: 846 },
{complexity: 2, check: "Yes", price1: 628, price2: 1136 },
{complexity: 2, check: "No",  price1: 
...

Votes

Translate

Translate
Adobe Employee ,
Nov 27, 2023 Nov 27, 2023

Copy link to clipboard

Copied

Hi @Badhawg66 

Hope you are doing well and thanks for reaching out.

The workflow you are trying to achieve is might be possible using JavaScript. For more information, please check the help pages listed below:
https://acrobatusers.com/tutorials/javascript_console/
https://helpx.adobe.com/acrobat/using/applying-actions-scripts-pdfs.html

Hope it will help

Regards
Amal

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 28, 2023 Nov 28, 2023

Copy link to clipboard

Copied

Could you help me delete my attachments? I tried attaching on to my post yesterday but it said I couldn't attach files. I can't edit my post yet.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 27, 2023 Nov 27, 2023

Copy link to clipboard

Copied

The best way to achieve this is to use a custom calculation script on the field that is assigned the Dollar amount value. 

If there is any complexity to the calculation, then you'll need to use "if" statements. 

Here are some relevant articles :

https://www.pdfscripting.com/public/How-to-Write-a-Basic-PDF-Calculation-Script.cfm?sd=40

https://www.pdfscripting.com/public/How-to-write-an-If-statement.cfm?sd=40

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 28, 2023 Nov 28, 2023

Copy link to clipboard

Copied

You can use this script as 'Custom calculation script', you can put it in "Text1" field.

Just finish list with all the prices.

var cpx = Number(this.getField("Complexity").valueAsString);
var chk = this.getField("Check Box").valueAsString;
var total1 = 0;
var total2 = 0;
var prices = [
{complexity: 1, check: "Yes", price1: 459, price2: 966 },
{complexity: 1, check: "No",  price1: 364, price2: 846 },
{complexity: 2, check: "Yes", price1: 628, price2: 1136 },
{complexity: 2, check: "No",  price1: 532, price2: 979 }
//Fill in list with rest of the complexity and prices.
];

for(var i in prices){
if(cpx == prices[i].complexity && chk == prices[i].check){
total1 = prices[i].price1;
total2 = prices[i].price2;}}

this.getField("Text1").value = total1;
this.getField("Text2").value = total2;

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 28, 2023 Nov 28, 2023

Copy link to clipboard

Copied

I filled in the rest of the values but I get a Syntax error saying I'm missing a ] after the element list on line 11. Did I do something wrong?

 

var cpx = Number(this.getField("Complexity").valueAsString);
var chk = this.getField("Check Box").valueAsString;
var total1 = 0;
var total2 = 0;
var prices = [
{complexity: 1, check: "Yes", price1: 459, price2: 966 },
{complexity: 1, check: "No", price1: 364, price2: 846 },
{complexity: 2, check: "Yes", price1: 628, price2: 1136 },
{complexity: 2, check: "No", price1: 532, price2: 979 }
{complexity: 3, check: "Yes", price1: 701, price2: 1353 },
{complexity: 3, check: "No", price1: 604, price2: 1208 },
{complexity: 4, check: "Yes", price1: 894, price2: 1280 },
{complexity: 4, check: "No", price1: 749, price2: 1124 }
{complexity: 5, check: "Yes", price1: 942, price2: 1414 },
{complexity: 5, check: "No", price1: 834, price2: 1293 },
{complexity: 6, check: "Yes", price1: 1136, price2: 1353 },
{complexity: 6, check: "No", price1: 918, price2: 1196 }
{complexity: 7, check: "Yes", price1: 1196, price2: 1498 },
{complexity: 7, check: "No", price1: 1052, price2: 1353 },
{complexity: 8, check: "Yes", price1: 1438, price2: 1449 },
{complexity: 8, check: "No", price1: 1124, price2: 1293 }
{complexity: 9, check: "Yes", price1: 1498, price2: 1631 },
{complexity: 9, check: "No", price1: 1221, price2: 1449 },
{complexity: 10, check: "Yes", price1: 1836, price2: 1643},
{complexity: 10, check: "No", price1: 1341, price2: 1498 }
];

for(var i in prices){
if(cpx == prices[i].complexity && chk == prices[i].check){
total1 = prices[i].price1;
total2 = prices[i].price2;}}

this.getField("Text1").value = total1;
this.getField("Text2").value = total2;

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 28, 2023 Nov 28, 2023

Copy link to clipboard

Copied

You are missing comma after } in these lines:

complexity: 2, check: "No", price1: 532, price2: 979 }

{complexity: 4, check: "No", price1: 749, price2: 1124 }

{complexity: 6, check: "No", price1: 918, price2: 1196 }

{complexity: 8, check: "No", price1: 1124, price2: 1293 }

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 28, 2023 Nov 28, 2023

Copy link to clipboard

Copied

LATEST

Thank you! 😃

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines