Copy link to clipboard
Copied
Hi Community, I am in need of some very simply explained 'how to'. I am trying to create a text field (called "reference") that automatically fills text in a PDF form based on the form users responses. The first question, is made up of toggle fields. The group is called "donations", the first option is "individual" the second "Club" the last "Other". I want the reference field to show either I, C, or O dependent on the selection of the toggle (so basically, "if donations.individual is selected, give me I, if donations.club is selected give me C"etc.). I have looked on here and found some info, but it all seems to involve calculations and/or Dropboxes, not simply text (I tried one of those but got nothing back). I would also need to know where I need to put any script that would give me the response I am looking for (sorry, I am o.k. with PDF's but not done any scrip writing at all before).
I never do things easy, so the same Reference I would also like to add a further field (can be separate if easier). This would be dependent on entries in other text fields. In this case the text field is called "Club ID" and if in the toggle (mentioned earlier) club is selected, then I want it to return the entry in the club ID field. Is any/all of this possible and if so, how. Very grateful for any responses!
Copy link to clipboard
Copied
By "Toggle Field" do you mean a Checkbox? Or Radio Buttons?
If you mean radio buttons then it's much simpler, and you don't need to write a script.
Make the "export value" of each radio button the value you want displayed in the text field.
then add a calculation to the text field. Use the simplified notation option. Just enter the field name of the radio button group. The name of the radio button group needs to be plain text with no spaces.
Here are some articles that explain how to do this further:
https://acrobatusers.com/tutorials/how-to-do-not-so-simple-form-calculations/
https://www.pdfscripting.com/public/Checkboxes-and-Radio-Buttons.cfm
Copy link to clipboard
Copied
Please post the exact name of the Adobe program you use so a Moderator may move this message to that forum
Copy link to clipboard
Copied
Oh, sorry, I have just signed up to Adobe DC standard.
Copy link to clipboard
Copied
By "Toggle Field" do you mean a Checkbox? Or Radio Buttons?
If you mean radio buttons then it's much simpler, and you don't need to write a script.
Make the "export value" of each radio button the value you want displayed in the text field.
then add a calculation to the text field. Use the simplified notation option. Just enter the field name of the radio button group. The name of the radio button group needs to be plain text with no spaces.
Here are some articles that explain how to do this further:
https://acrobatusers.com/tutorials/how-to-do-not-so-simple-form-calculations/
https://www.pdfscripting.com/public/Checkboxes-and-Radio-Buttons.cfm
Copy link to clipboard
Copied
Hi Thom, I meant radio button for the first field but I am clearly out of my depth here. I have created a field box, where I want the responses from the buttons to show (and no way to override, but can't work that one out - sure that's only a matter of searching). I changed the buttons to just stated "I", "C", "D" and "O". I made the entry required so anyone filling out the form definitely has to tick one of these.
But I am stumped how I now get this response into the text box now. I looked at your two docs, but I am clearly missing something here. The radio button group is simply called "Who" and now selections are just the letters. I want the text box to just give me one of those four, but just can't work out how to achieve that. I tried just entering "Who" or just "Who_I" but that doesn't achieve anything... can you give me a little bit more on this?
Copy link to clipboard
Copied
Hi Thom, I have persevered and found another helpful thread on a similar note. Clearly not as elegant or as simple as your suggestion, but I managed both my fields (there's a third one coming, whith a bit more complication, but I managed these two, so here we go).
I used a Custom calculation script which was simply:
if(this.getField("Who").value=="I"){event.target.value="I"} else if(this.getField("Who").value=="C"){event.target.value="C"}
and so on.
In my other field, I needed the selection above to be right, but to give me the entry of a different field. For that I used:
if(this.getField("Who".value=="I"{event.value=this.getField("Membership_ID").value}
and so on, for all the other ones.
Both are working very nicely.
The next one I need is more complicated, as it relies on an entry greater than 0 in a particular field to populate with some specific letters. But I think I can find how to do this from the paperwork you had sent me to look at.
Thanks again, even though I ended up using a different solution this has still been helpful and your time writing back has been greatly appreciated.
Copy link to clipboard
Copied
How about this for the calculation?
event.value = this.getField("Who").value;
NEVER, EVER use "event.target.value" in a calculation script
Copy link to clipboard
Copied
Hi Thom,
thanks for this, as this should make things easier, however, please can you explain to me WHY I should never use that skript in this way? It works and if I should not use it , then I need to check (on my work PC) if I used it on any of my other skripts that might need changing. Thus would be good to understand why a pro tells me not to. Thanks in advance.
Copy link to clipboard
Copied
When using a calculation script, values are returned to field through event.value. At this point the value of the field has not changed, there are two other events that have to be run before the real value of the field is settled, validate and format. So you see there is a sequence of events that is happening inside the field. "event.target" is a reference to the field. And "event.target.value" references the field value from the outside. If you set a field value from the outside, from a script running inside, it triggers more events. Events that will reduce performance, trip over one another and throw off the event sequence, and potentially cause infinate loops and crash Acrobat.
In programming its very important to stick to the rules.
Copy link to clipboard
Copied
Thank you so much for this additional explanation. I have checked my other skripts and replaced the "event.target.value" with "event.value" and they all still work. And as you mentioned, I think they do indeed work neater.
Thanks again, I really greatly appreciate this.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more