• 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

14.5K

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

Copy link to clipboard

Copied

Yes, that's easily done. For example, let's say you have a check-box called "Checkbox1" and you want to populate a field called "Text1" with 500 if it's checked, and zero otherwise.

Use this code as the custom calculation script of Text1:

event.value = (this.getField("Checkbox1").value=="Off") ? 0 : 500;

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

Copy link to clipboard

Copied

WOW! Thank you @try67— may I ask how to complete it if there are two choices? So if one box is checked, it's 500, and if the other box is checked it's 700?

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

Copy link to clipboard

Copied

I tried using this:

event.value = (this.getField("fullpageexhibitor").value=="Off") ? 0 : 500;

event.value = (this.getField("fullpageadregular").value=="Off") ? 0 : 700;

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

Copy link to clipboard

Copied

No, that won't work... What if both boxes are ticked?

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

Copy link to clipboard

Copied

They can only choose one box (either 500 or 700)

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

YES!!!! You're a genius and a scholar and my hero!!!!!!! Thank you try67​ !!!!!

May I ask for another scenario? They also have an input field where they can enter certain booth numbers that are premium prices, so if they enter 301, the price is $1,000, if they enter 302 the price is $1,200 -- how would you do that or can that be done? In this case, the user enters a specific number

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

Copy link to clipboard

Copied

You can use something like this:

if (this.getField("boothnumber").valueAsString=="301") event.value=1000;

if (this.getField("boothnumber").valueAsString=="302") event.value=1200;

etc.

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

Copy link to clipboard

Copied

You're my BEST FRIEND! Thank you try67​!!! That worked, BUT the user can actually enter more than one booth number (maximum 3) in that one field (separated by a comma) -- is it possible to add the amounts?

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

Copy link to clipboard

Copied

Yes, but this is getting more complicated...

On Sat, Sep 23, 2017 at 9:59 PM, sasegars58 <forums_noreply@adobe.com>

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

Copy link to clipboard

Copied

If you wish I can create this script for you, for a small fee. You can send me the full specs to try6767 at gmail.com and we could discuss the details.

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 ,
Feb 16, 2022 Feb 16, 2022

Copy link to clipboard

Copied

I have several boxes and they can check more than 1, how do I sum up the value of their choices? 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 Expert ,
Feb 17, 2022 Feb 17, 2022

Copy link to clipboard

Copied

Please post a more detailed explanation to a new thread.

There are many different ways to add-up checkbox selections. The exact solution depends on the exact details. 

Also, you might start by learning a bit more about scripting PDF checkboxes:

https://www.pdfscripting.com/public/Checkboxes-and-Radio-Buttons.cfm

 

 

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 ,
Feb 17, 2022 Feb 17, 2022

Copy link to clipboard

Copied

Thanks, I created radio checkboxes (for options where they can only choose 1) and regular checkboxes and assigned different values for each checkbox. I was then able to sum up the values based on their choices.

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

Copy link to clipboard

Copied

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 ,
Jul 18, 2022 Jul 18, 2022

Copy link to clipboard

Copied

Thanks for this, I just have one question, what do i put in when it says "Line Number"? I tried Textbox29 which is where the total will go, nothing happens

 

Also I need to total a number of text boxes, is this possible? 

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