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

Calculation resulting from checkbox selection in pdf

Explorer ,
Sep 23, 2017 Sep 23, 2017

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
21.5K
Translate
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
1 ACCEPTED SOLUTION
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;

View solution in original post

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

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";

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

Change:

replace("Off","No")

To:

replace("Off","")

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

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?

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

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

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

etc.

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

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";

 

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

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

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?

 

 

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

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

Translate
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

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;

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

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

Translate
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

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;

Translate
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

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.

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

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

Translate
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

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;

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

Add "\r" before it...

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

"\rReviewers\r"

Translate
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

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.

Translate
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

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. 

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

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

Translate
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

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

 

 

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

Can you share it?

Translate
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

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" ?

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

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

Translate
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

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

Translate
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