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

Calculation resulting from checkbox selection in pdf

Explorer ,
Sep 23, 2017 Sep 23, 2017

Copy link to clipboard

Copied

I'm probably way out of my league here, but here's what I need to happen:

I have a fillable pdf with several checkboxes that would result in an amount being added to a total field (Ex: Full page ad / Exhibitor fee is $500 / Non exhibitor fee is $750), so the user selects two items (or none). If they check "Full page ad" checkbox, then they select whether or not they are an exhibitor, then the amount ($500) would go to the total field = $500. And several more optional add choices, etc.

So, I guess my question(s) are:

If a checkbox is selected, can a number populate in a separate field? And if so, how?

I am a javascript beginner, have only completed the calculations that were simple.

Many thanks in advance for help/advice.

TOPICS
PDF forms

Views

19.2K

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 , Sep 23, 2017 Sep 23, 2017

Then use this:

event.value = 0;

if (this.getField("fullpageexhibitor").value!="Off") event.value=500;

else if (this.getField("fullpageadregular").value!="Off") event.value=700;

Votes

Translate

Translate
Community Beginner ,
Jun 14, 2024 Jun 14, 2024

Copy link to clipboard

Copied

I'm all done! Thank you for your help!

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 Beginner ,
Jun 14, 2024 Jun 14, 2024

Copy link to clipboard

Copied

LATEST

I'm all done! Thank you for your help!

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 Beginner ,
Jul 07, 2019 Jul 07, 2019

Copy link to clipboard

Copied

I'm trying to do a similar thing but I'm having trouble adapting the following code to my situation...

event.value = 0;

if (this.getField("CheckBox1#0").value!="Off") event.value=120;

else if (this.getField("CheckBox1#1").value!="Off") event.value=450;

I have a suspicion it's because I'm using multiple checkboxes that have the same name but with different export values (to simulate radio button operation) and the checkbox name has a # in it.

Am I able to replace the checkbox name "CheckBox1#0" with the export value instead?

Also, to make matters worse I have 5 checkboxes that can all be different values (although 2 are the same) and I need the textbox to display the value of the selected checkbox.

I assume it's something like this (although I'm sure the syntax is incorrect)...

event.value = 0;

if (this.getField("CheckBox1#0").value!="Off") event.value=120;

else if (this.getField("CheckBox1#1").value!="Off") event.value=450;

else if (this.getField("CheckBox1#2").value!="Off") event.value=200;

else if (this.getField("CheckBox1#3").value!="Off") event.value=300;

else if (this.getField("CheckBox1#4").value!="Off") event.value=450;

Any help would be appreciated.

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 ,
Jul 07, 2019 Jul 07, 2019

Copy link to clipboard

Copied

What are the actual export values of these check-box fields?

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 Beginner ,
Jul 07, 2019 Jul 07, 2019

Copy link to clipboard

Copied

Assessment, Capstone, Low, Medium, High

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 ,
Jul 07, 2019 Jul 07, 2019

Copy link to clipboard

Copied

Then you should use those values in your code, and drop the "#1", "#2", etc. notation. Something like this:

event.value = 0;

if (this.getField("CheckBox1").valueAsString=="Assessment") event.value=120;

else if (this.getField("CheckBox1").valueAsString=="Capstone") event.value=450;

// etc.

else event.value = "";

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 Beginner ,
Jul 07, 2019 Jul 07, 2019

Copy link to clipboard

Copied

Like magic! Thanks very much.

I had tried that previously but I didn't use the "==". Just one "=".

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 ,
Jul 07, 2019 Jul 07, 2019

Copy link to clipboard

Copied

That's a common mistake. That assigns one value to another, not compare them.

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
New Here ,
Mar 06, 2023 Mar 06, 2023

Copy link to clipboard

Copied

Hi there, just jumping on the bandwagon here. I think im also trying to do something similar - adding a total to a number of radio checkboxes. Ive got the checkboxes adding a $ value, but cant figure out how to calculate the total cost into a field if the user selects more than one option.

 

Code is:

 

event.value = 0;

if (this.getField("CheckBox1").value!="Off") event.value=165.60;

if (this.getField("CheckBox2").value!="Off") event.value=165.60;

if (this.getField("CheckBox3").value!="Off") event.value=165.60;

if (this.getField("CheckBox4").value!="Off") event.value=165.60;

if (this.getField("CheckBox5").value!="Off") event.value=621.00;

 

Screen Shot 2023-03-07 at 1.39.30 pm.png

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 ,
Mar 07, 2023 Mar 07, 2023

Copy link to clipboard

Copied

After the first line, change all instances of event.value = ... to event.value+= ...

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 ,
Dec 23, 2023 Dec 23, 2023

Copy link to clipboard

Copied

There's a much easier way.  Create one check box ("CheckBox") then use right-click > Create Create Multiple Copies to create the rest of the fields (named "CheckBox.0" through "CheckBox.10").  Set the export values to the dollar amounts for each box.  In the Subtotal field, calculation tab, use "Value is the sum of" and select the field "CheckBox".  Done.  Here's a step by step guide with video:

https://pdfautomationstation.substack.com/p/create-a-check-box-scoring-questionnaire

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 Beginner ,
Dec 23, 2023 Dec 23, 2023

Copy link to clipboard

Copied

hank you for your inquiry. To provide you with the accurate export values of the checkbox fields, we would need more specific details about the checkboxes in question. Each checkbox can be customized to have its own export value based on the requirements of the form or system you are using.

Please provide the names or descriptions of the checkbox fields you are referring to, and any additional context that might help us assist you better. Once we have more information, we will be able to furnish you with the precise export values for the specified checkboxes.

Looking forward to your clarification.

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 Beginner ,
Dec 23, 2023 Dec 23, 2023

Copy link to clipboard

Copied

I resolved it by making hidden fields and using a script someone else gave me earlier. But I will look at this one and see if it fits better for the long run.

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
New Here ,
Sep 21, 2019 Sep 21, 2019

Copy link to clipboard

Copied

Hi there

 

I've been searching the community and this thread is the closest I found regarding what I'm trying to achieve. I am very rusty with my script knowledge as I haven't practiced it for years; I'm practically beginner level at this point. I have a similar situation where I have a list of services (with checkboxes) that have the same pricing; however, I do want multiple selections added up to a total. 

 

The form allows the client to choose from 3 Service Package deals (Packages 1 to 3). Currently I have these as radio buttons where they can only select one. For the sake of math I'll keep the pricing simple: Packages 1 to 3 are $5000, $3000, and $1000 respectively. Each service package offers discounts on additional services. Package1 offers $1000 discount, Package2 $500, and Package3 no discount. The group of radio buttons is named "Group1" and their button choices are 1, 2, & 3 respectively.

 

There are 5 additional services, Services A to E. The client filling up the form can choose to select as many services, including none. Each service costs $500. However, depending on the Package deal they selected earlier in the form (Packages 1 to 3), they get 2 ($1000) or 1 ($500) services discounted. I would like to autofill the text field named "TotalExtras" so the client would instantly know how much extra on top of the base Package they have chosen.

 

First Example:

Client selects Package2 for $3000 (which will discount $500 from total extras). The client continues to next section and selects three additional services, say A, B & D. So the three choices should total $1500 ($500 each). But because they have chosen Package2, the autofill total in the TotalExtras text field should read "$1000" ($1500 additional services minus $500 Package2 discount). 

 

Second Example:

Client selects Package1 for $5000 (which will discount $1000 from total extras). The client continues to next section and selects only one additional service, they choose C. The single choice should total $500. But because they have chosen Package1, the autofill total in the TotalExtras text field should read "$0" ($500 additional services minus $1000 Package1 discount). The total for this TotalExtras field should never be negative and there is no option to go lower than the base price of the chosen Package.

 

Is this posssible? Or am I asking for too much? Also, am I supposed to have all the checkboxes under one name? They all currently have separate names.

 

Thanks in advance!

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
New Here ,
Jun 07, 2020 Jun 07, 2020

Copy link to clipboard

Copied

I have a similar issue... this is the code im trying to use, Im trying to get a check box in adobe to (When checked) to subtract "TTLCalculated" And use that value in the next part of my code, wanted to know if what im doing wrong, im a newbie to javascript, would really appreciate the help!

 

var DA = Number(this.getField("Downpayment*").valueAsString);

var DA2 = Number(this.getField("TTLCalculated").valueAsString);

event.value = (DA-DA2);

if (this.getField("TTLCalculated").value!="Off") event.value=(DA-DA2);

else if (this.getField("TTLCalculated").value!="Off") event.value=0;

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 ,
Jun 08, 2020 Jun 08, 2020

Copy link to clipboard

Copied

YOu have exactly the same condition in both parts of the if block. Remove the second if. Just use an else.

 

 

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
New Here ,
Jan 20, 2021 Jan 20, 2021

Copy link to clipboard

Copied

Hello,

 

I am trying to do something similar. I have a specific rate that gets calculated on top of the total amount. However, the payment type changes the rate.

At the moment All payment types has a rate of 8.42% added to the total amount which is annotated in the G&A (named 5 on the PDF) i have added using the simplified filed notation which is TOTAL_COST * 0.0842, this will happen regardless the payment type. However, for three payment types its 7.67% added cost and one is 9.55% added cost. How do I have the specific rate calculation work with the specific payment type selected?

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 Beginner ,
Dec 23, 2023 Dec 23, 2023

Copy link to clipboard

Copied

I am trying to do something similar but I think I am missing something.

Mine seems like it would be basic.

Text 1 = Text 2 +(5 if Checkbox 1 is checked) + (5 if Checkbox 2 is checked) + Text 3 + Text 4

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 ,
Dec 23, 2023 Dec 23, 2023

Copy link to clipboard

Copied

Is that the script you are using?

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 Beginner ,
Dec 23, 2023 Dec 23, 2023

Copy link to clipboard

Copied

No, that is the end result I want to create. I am very new to editing Adobe but want to start making more use of this program I am paying for.

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 ,
Dec 23, 2023 Dec 23, 2023

Copy link to clipboard

Copied

Set the export values of Checkbox 1 and Checkbox 2 to 5.  In the calculation tab of Text 1, select Value is the sum of, then select the following fields:  Text 2, Checkbox 1, Checkbox 2, Text 3, and Text 4.  This might help you learn how this works:

https://pdfautomationstation.substack.com/p/create-a-check-box-scoring-questionnaire

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 Beginner ,
Dec 23, 2023 Dec 23, 2023

Copy link to clipboard

Copied

Thanks

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 Beginner ,
Dec 23, 2023 Dec 23, 2023

Copy link to clipboard

Copied

// Add this script to the "Custom Calculation Script" of the total field

var total = 0;

// Function to update total based on checkbox selections
function updateTotal() {
total = 0;

// Check each checkbox and update total accordingly
if (this.getField("fullPageAd").value === "Yes") {
if (this.getField("exhibitor").value === "Yes") {
total += 500; // Full page ad exhibitor fee
} else {
total += 750; // Full page ad non-exhibitor fee
}
}

// Add more conditions for other checkboxes if needed

// Update the total field
this.getField("totalField").value = total;
}

// Set up event listeners for each checkbox
this.getField("fullPageAd").setAction("MouseUp", updateTotal);
this.getField("exhibitor").setAction("MouseUp", updateTotal);

// Add more event listeners for other checkboxes as needed

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