Highlighted

Calculation resulting from checkbox selection in pdf

Community Beginner ,
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.

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

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;

Topics

Macintosh, PDF forms

Views

4.1K

Likes

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

Calculation resulting from checkbox selection in pdf

Community Beginner ,
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.

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

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;

Topics

Macintosh, PDF forms

Views

4.1K

Likes

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
Most Valuable Participant ,
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;

Likes

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
Reply
Loading...
Community Beginner ,
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?

Likes

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
Reply
Loading...
Community Beginner ,
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;

Likes

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
Reply
Loading...
Most Valuable Participant ,
Sep 23, 2017

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
Community Beginner ,
Sep 23, 2017

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
Most Valuable Participant ,
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;

Likes

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
Reply
Loading...
Community Beginner ,
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

Likes

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
Reply
Loading...
Most Valuable Participant ,
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.

Likes

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
Reply
Loading...
Community Beginner ,
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?

Likes

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
Reply
Loading...
Most Valuable Participant ,
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>

Likes

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
Reply
Loading...
Most Valuable Participant ,
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.

Likes

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
Reply
Loading...
Community Beginner ,
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.

Likes

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
Reply
Loading...
Most Valuable Participant ,
Jul 07, 2019

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
Community Beginner ,
Jul 07, 2019

Copy link to clipboard

Copied

Assessment, Capstone, Low, Medium, High

Likes

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
Reply
Loading...
Most Valuable Participant ,
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 = "";

Likes

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
Reply
Loading...
Community Beginner ,
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 "=".

Likes

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
Reply
Loading...
Most Valuable Participant ,
Jul 07, 2019

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
New Here ,
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!

Likes

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
Reply
Loading...
New Here ,
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;

Likes

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
Reply
Loading...
Adobe Community Professional ,
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.

 

 

Likes

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
Reply
Loading...