Copy link to clipboard
Copied
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.
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!
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Thanks a lot for your quick reply! Sounds really interesting, but where can I set the export value?
Copy link to clipboard
Copied
Under the Options tab of the field's Properties dialog.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
I mean of course screenshot of the field's properties dialog 🙂
Copy link to clipboard
Copied
There you use the export value "Auswahl1".
Copy link to clipboard
Copied
Oh OK, that's it? Alright, let me try that one 👍👍
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
The code I provided will do that...
Copy link to clipboard
Copied
Oh ok, I'll try immediately 😉
Copy link to clipboard
Copied
In the next step I need a new field to sum up all selected field values, like in this example:
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!!
Copy link to clipboard
Copied
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)
Copy link to clipboard
Copied
YOU'RE SOOOO GREAT MAN!!! I would never have come up with such an idea, so good! I'll try it now 🙂
Copy link to clipboard
Copied
WORKS FLAWLESSLY!!!
I have only a few more small things to do:
I think for this I need an if/else?? How can I do that?
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
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:
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
To remove 0 and show blank as validation script of that field use this:
if(event.value == 0)event.value = "";
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Don't combine them, put calculation in calculation and script to remove 0 in validation.
Copy link to clipboard
Copied
very very nice! Didn't know about validation! That's great!!! Thanks!
Copy link to clipboard
Copied
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:
Copy link to clipboard
Copied
What are those field names and will radio Option 2 always be on first row or it depends which you check first?
Copy link to clipboard
Copied
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:
maybe this is better to understand now.
Names for example just like try67 wrote:
Radio1, Radio2, Radio3, CheckBox1, CheckBox2
Find more inspiration, events, and resources on the new Adobe Community
Explore Now