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

Acrobat forms if radio buttons and checkboxes checked

Explorer ,
Jun 23, 2022 Jun 23, 2022

Hi everybody,

I'm trying to create an acrobat form for the first time with some JS code. I'm trying since two days now, but somehow cannot figure out how to check if radio buttons and checkboxes are checked and then do a specific calculation.

Acrobat calculation.png

The form looks like this. In the last field should come a calculation with the values of the fields above. So for example if radio option 2 and first checkbox are check the total value is 60, so in the bottom field has to be "9" (15% of 60).

 

Hope somebody here can help me out with this.

 

Appreciate any help or advice you could give.

 

Thanks a lot in advance!

TOPICS
How to , JavaScript , PDF forms
6.0K
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 23, 2022 Jun 23, 2022

You actually don't need a script. If you've applied those values as the export values of the fields then you can use this formula under the Simplified Field Notation option of the last field (you didn't specify the field names, so let's say they are Radio1, CheckBox1 and CheckBox2:

 

(Radio1 + CheckBox1 + CheckBox2) * 0.15

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
Explorer ,
Jun 23, 2022 Jun 23, 2022

Thanks a lot for your quick reply! Sounds really interesting, but where can I set the export value?

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 23, 2022 Jun 23, 2022

Under the Options tab of the field's Properties dialog.

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
Explorer ,
Jun 23, 2022 Jun 23, 2022

Yeah, I searched for this already, but didn't find anything like that there. Here is a screenshot of my Acrobat. It's in German, but I assume it should at least look similar in the English version.

Acrobat-Pro-form.jpg

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
Explorer ,
Jun 23, 2022 Jun 23, 2022

I mean of course screenshot of the field's properties dialog 🙂

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 23, 2022 Jun 23, 2022

There you use the export value "Auswahl1".

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
Explorer ,
Jun 23, 2022 Jun 23, 2022

Oh OK, that's it? Alright, let me try that one 👍👍

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
Explorer ,
Jun 24, 2022 Jun 24, 2022

Alright, yes that works nicely! Thanks!! So now I have just added the values. But how can I now calculate the 15% in the new bottom field? Can you please give me the script for that? I know I'm brand new to JS on PDF and really don't know how to address the fields.

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 24, 2022 Jun 24, 2022

The code I provided will do that...

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
Explorer ,
Jun 24, 2022 Jun 24, 2022

Oh ok, I'll try immediately 😉

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
Explorer ,
Jun 24, 2022 Jun 24, 2022

In the next step I need a new field to sum up all selected field values, like in this example:

Acrobat calculation.png

So the checkbox of the 15% field does not have a fixed export value. It can change depending what is selected before. How can I achieve that calculation? Thanks a lot!!

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 24, 2022 Jun 24, 2022

OK, I see. You can make it work if you set the export value of the check-box to 1 and then multiply it by the value of the text field that shows the 15% value. For example:

 

Radio1 + CheckBox1 + CheckBox2 + (Text15Percent * CheckBox2)

 

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
Explorer ,
Jun 24, 2022 Jun 24, 2022

YOU'RE SOOOO GREAT MAN!!! I would never have come up with such an idea, so good! I'll try it now 🙂

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
Explorer ,
Jun 24, 2022 Jun 24, 2022

WORKS FLAWLESSLY!!! 

 

I have only a few more small things to do:

  • Right now if nothing is selected in the calculated fields there is a "0". Can it be done that there is no "0" visible? So only show a number if above 0 or something like that? Or not visible if "0"??
  • The values are amounts of money, so I need to have seperators, for USD it's the " . ", for EUR it's the " , " and for CHF it's " ' " for Example "2,500.20 USD" written in EUR would be "2.500,50 EUR" and in CHF it is "2'500.50 CHF". How can I include these seperators in the calculated fields? Right now I am doing the file for CHF.
  • For the calculated fields, how can I add the currency at the end? Right now "CHF". I tried with + "CHF" but then it does not do the calculation anymore.
  • On the next page I want to have a summary of all selected fields. So for example if  radio option 2 is selected there should be the export value of radio option 2 description and then in front of that the export value of radio option 2. About that:

      Acrobat calculation summary.png

          I think for this I need an if/else?? How can I do that?

  

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
Explorer ,
Jun 24, 2022 Jun 24, 2022

I found the option how to set the currency 🙂

But there is one problem with that. When I set the text flush right, I cannot set currency (here CHF) to be at the right side with a space in between. When I set right side without space, it works, but with space it jumps to left side again. Crazy!

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 24, 2022 Jun 24, 2022

I tried it with CHF as the currency, aligned to the right, and set to be after the text with a space, and it appears fine:

 

try67_0-1656065292796.png

 

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
Explorer ,
Jun 24, 2022 Jun 24, 2022

OK.... crazy it doesn't work for me! I'll try again.... otherwise I can also set all other fields before the number and it fine, so not a very big deal.

 

But, can you help me out with the other issues?

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 24, 2022 Jun 24, 2022

To remove 0 and show blank as validation script of that field use this:

if(event.value == 0)event.value = "";

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
Explorer ,
Jun 24, 2022 Jun 24, 2022

Thanks for joining Nesa! 

How can I combine this with this: (Radio1 + CheckBox1 + CheckBox2) * 0.15

 

That means, if any of the radio buttons or checkboxes above are selected, the value here cannot be 0, so then it does the calculation. But if nothing is selected, value is 0 and should not be shown.

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 24, 2022 Jun 24, 2022

Don't combine them, put calculation in calculation  and script to remove 0 in validation.

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
Explorer ,
Jun 24, 2022 Jun 24, 2022

very very nice! Didn't know about validation! That's great!!! Thanks!

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
Explorer ,
Jun 24, 2022 Jun 24, 2022

Only one more thing to solve now:

On the next page I want to have a summary of all selected fields. So for example if  radio button option 2 is selected there should be the export value of radio option 2 description and then in front of that the export value of radio option 2. I hope my stupid explanation is understandable 🙂 About that:

Acrobat calculation summary.png

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 24, 2022 Jun 24, 2022

What are those field names and will radio Option 2 always be on first row or it depends which you check 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
Explorer ,
Jun 24, 2022 Jun 24, 2022

radio option will always be on first row. So if button 1 is selected, there should be the value for option 1 and so on.... I just wrote option 2 here, because I had it like that in the example above also. Here is the full example:

Acrobat calculation full.png

maybe this is better to understand now.

 

Names for example just like try67 wrote:

Radio1, Radio2, Radio3, CheckBox1, CheckBox2

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