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.
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;
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;
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?
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;
Copy link to clipboard
Copied
No, that won't work... What if both boxes are ticked?
Copy link to clipboard
Copied
They can only choose one box (either 500 or 700)
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;
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
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.
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?
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>
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.
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.
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
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.
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?
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.
Copy link to clipboard
Copied
What are the actual export values of these check-box fields?
Copy link to clipboard
Copied
Assessment, Capstone, Low, Medium, High
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 = "";
Copy link to clipboard
Copied
Like magic! Thanks very much.
I had tried that previously but I didn't use the "==". Just one "=".
Copy link to clipboard
Copied
That's a common mistake. That assigns one value to another, not compare them.
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;
Copy link to clipboard
Copied
After the first line, change all instances of event.value = ... to event.value+= ...
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!