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

# Calculation resulting from checkbox selection in pdf

Explorer ,
Sep 23, 2017 Sep 23, 2017

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.

TOPICS
PDF forms

Views

17.2K

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

Then use this:

event.value = 0;

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

72 Replies 72
New Here ,
Jun 13, 2024 Jun 13, 2024

Copied

Okay, it's working now! Below is the code. If I don't select a box, it lists No. What do I change ("Off","No") to to get rid of that?

event.value=

"Client Services\r"+

this.getField("ClientServicesQ1").value.replace("Off","No") +"\r"+

this.getField("ClientServicesQ2").value.replace("Off","No") +"\r\r"+

"Reviewers\r"+

this.getField("CSReviewer1of5").value.replace("Off","No") +"\r"+

this.getField("CSReviewer2of5").value.replace("Off","No") +"\r"+

this.getField("CSReviewer3of5").value.replace("Off","No") +"\r"+

this.getField("CSReviewer4of5").value.replace("Off","No") +"\r"+

this.getField("CSReviewer5of5").value.replace("Off","No") +"\r\r";

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 Expert ,
Jun 13, 2024 Jun 13, 2024

Copied

Change:

replace("Off","No")

To:

replace("Off","")

Report

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

Copied

Okay, that worked, but it's like the space is still reserved. So if I selected only the 5th check box there are give blank line spaces in the summary area. Is there a code that just lists them as they are checked but without a replace command?

Report

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

Copied

I have already written the code for you previously in this thread:

this.getField(""ClientServicesQ1").value!="Off"?this.getField("ClientServicesQ1").value+"\r":""+

etc.

Report

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

Copied

That one isn't working. The one Try67 gave me is working but I just need it to stop listing No when the checkbox isn't selected. Even when I delete No and use " ", the blank line is there like it's still recognizing the line. I want it to just shift the next item up if nothing is selected.

event.value=

"Client Services\r"+

this.getField("ClientServicesQ1").value.replace("Off","No") +"\r"+

this.getField("ClientServicesQ2").value.replace("Off","No") +"\r\r"+

"Reviewers\r"+

this.getField("CSReviewer1of5").value.replace("Off","No") +"\r"+

this.getField("CSReviewer2of5").value.replace("Off","No") +"\r"+

this.getField("CSReviewer3of5").value.replace("Off","No") +"\r"+

this.getField("CSReviewer4of5").value.replace("Off","No") +"\r"+

this.getField("CSReviewer5of5").value.replace("Off","No") +"\r\r";

Report

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

Copied

Successfully tested:

``````var line1=this.getField("ClientServicesQ1").value!="Off"?this.getField("ClientServicesQ1").value+"\r":"";
var line2=this.getField("ClientServicesQ2").value!="Off"?this.getField("ClientServicesQ2").value+"\r":"";
var line3=this.getField("CSReviewer1of5").value!="Off"?this.getField("CSReviewer1of5").value+"\r":"";
var line4=this.getField("CSReviewer2of5").value!="Off"?this.getField("CSReviewer2of5").value+"\r":"";
var line5=this.getField("CSReviewer3of5").value!="Off"?this.getField("CSReviewer3of5").value+"\r":"";
var line6=this.getField("CSReviewer4of5").value!="Off"?this.getField("CSReviewer4of5").value+"\r":"";
var line7=this.getField("CSReviewer5of5").value!="Off"?this.getField("CSReviewer5of5").value+"\r":"";
event.value=
"Client Services\r"+line1+line2+"Reviewers\r"+line3+line4+line5+line6+line7;``````

Report

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

Copied

thank you! That works perfectly. I need to do 12 more. When I start with the next one on the next line it breaks. Is there anything I need to add between the two?

Report

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

Copied

Are you saying your code breaks, or want the line to break?

Report

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

Copied

It breaks when I paste this below it:

var line1=this.getField("DevelopmentQ1").value!="Off"?this.getField("DevelopmentQ1").value+"\r":"";

var line6=this.getField("DevReviewer1of2").value!="Off"?this.getField("DevReviewer1of2").value+"\r":"";

var line7=this.getField("DevReviewer2of2").value!="Off"?this.getField("DevReviewer2of2").value+"\r":"";

event.value=

"Development\r"+line1+"Reviewers\r"+line2+line3;

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

Copied

Post the full code, and explain what you mean by "it breaks"... What exactly happens?

Report

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

Copied

Okay, the first code you gave me worked. It listed:

Client Services

Q1 Value (the question I want it to show)

Reviewers

Reviewers names

Then when I added on the next one (Development) and I check the boxes for both Client Services and Devlopment, only Development shows (it does listed everything correctly). If I only click the boxes for Client Services, it only shows the label. Here is the full code:

var line1=this.getField("ClientServicesQ1").value!="Off"?this.getField("ClientServicesQ1").value+"\r":"";

var line2=this.getField("ClientServicesQ2").value!="Off"?this.getField("ClientServicesQ2").value+"\r":"";

var line3=this.getField("CSReviewer1of5").value!="Off"?this.getField("CSReviewer1of5").value+"\r":"";

var line4=this.getField("CSReviewer2of5").value!="Off"?this.getField("CSReviewer2of5").value+"\r":"";

var line5=this.getField("CSReviewer3of5").value!="Off"?this.getField("CSReviewer3of5").value+"\r":"";

var line6=this.getField("CSReviewer4of5").value!="Off"?this.getField("CSReviewer4of5").value+"\r":"";

var line7=this.getField("CSReviewer5of5").value!="Off"?this.getField("CSReviewer5of5").value+"\r":"";

event.value=

"Client Services\r"+line1+line2+"Reviewers\r"+line3+line4+line5+line6+line7;

var line8=this.getField("DevelopmentQ1").value!="Off"?this.getField("DevelopmentQ1").value+"\r":"";

var line9=this.getField("DevReviewer1of2").value!="Off"?this.getField("DevReviewer1of2").value+"\r":"";

var line10=this.getField("DevReviewer2of2").value!="Off"?this.getField("DevReviewer2of2").value+"\r":"";

event.value=

"Development\r"+line8+"Reviewers\r"+line9+line10;

Report

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

Copied

Also, that last message is old - I replied to the notification email and I guess there is a lag. The latest message is the one above it - me telling you what I mean by broken and giving th3 full code.

Report

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

Copied

event.value is one value for the entire field, so if you have it twice the 2nd will overwrite the first.

Report

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

Copied

Thanks! The below code works. Now how do I get an line space before each group label (before Development).

var line1=this.getField("ClientServicesQ1").value!="Off"?this.getField("ClientServicesQ1").value+"\r":"";

var line2=this.getField("ClientServicesQ2").value!="Off"?this.getField("ClientServicesQ2").value+"\r":"";

var line3=this.getField("CSReviewer1of5").value!="Off"?this.getField("CSReviewer1of5").value+"\r":"";

var line4=this.getField("CSReviewer2of5").value!="Off"?this.getField("CSReviewer2of5").value+"\r":"";

var line5=this.getField("CSReviewer3of5").value!="Off"?this.getField("CSReviewer3of5").value+"\r":"";

var line6=this.getField("CSReviewer4of5").value!="Off"?this.getField("CSReviewer4of5").value+"\r":"";

var line7=this.getField("CSReviewer5of5").value!="Off"?this.getField("CSReviewer5of5").value+"\r":"";

var line8=this.getField("DevelopmentQ1").value!="Off"?this.getField("DevelopmentQ1").value+"\r":"";

var line9=this.getField("DevReviewer1of2").value!="Off"?this.getField("DevReviewer1of2").value+"\r":"";

var line10=this.getField("DevReviewer2of2").value!="Off"?this.getField("DevReviewer2of2").value+"\r":"";

event.value=

"Client Services\r"+line1+line2+"Reviewers\r"+line3+line4+line5+line6+line7+"Development\r"+line8+"Reviewers\r"+line9+line10;

Report

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

Copied

It breaks when I paste this below it:

var line1=this.getField("DevelopmentQ1").value!="Off"?this.getField("DevelopmentQ1").value+"\r":"";

var line6=this.getField("DevReviewer1of2").value!="Off"?this.getField("DevReviewer1of2").value+"\r":"";

var line7=this.getField("DevReviewer2of2").value!="Off"?this.getField("DevReviewer2of2").value+"\r":"";

event.value=

"Development\r"+line1+"Reviewers\r"+line2+line3;

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

Copied

Report

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

Copied

"\rReviewers\r"

Report

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

Copied

Thanks! when I'm typing the code in notepad and the link gets to be too long, how can I continue on the next line? A simple return doesn't seem to work.

Report

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

Copied

I think it's working using Retirn now. This thing is so sensitive. I'll make a change and it won't update and then I'll have to delete it and re enter it a few time for it to work. Like it saves a cache or something.

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

Copied

If the other fields have a calculated value check the fields calculation order, under More in Prepare Form mode.

Report

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

Copied

The checkboxes have an Export Value. The Summary field (text field) has the custom calculation script.

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

Copied

Can you share it?

Report

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

Copied

Its going well now. I haven't had an issue on tha last three! How do I add bold to "Client Services\r" and "\rCompliance\r" ?

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

Copied

That is much more complicated. You will need to use Rich Text Formatting instead of plain text.

Report

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

Copied

I'll leave it as is. Not starting over lol.