Skip to main content
Known Participant
May 22, 2020
Answered

If/then statement in text fields

  • May 22, 2020
  • 2 replies
  • 6359 views

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!

This topic has been closed for replies.
Correct answer Thom Parker

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

 

2 replies

Thom Parker
Thom ParkerCorrect answer
Inspiring
May 23, 2020

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

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Known Participant
May 26, 2020

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?

 

Known Participant
May 26, 2020

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. 

John T Smith
Braniac
May 22, 2020

Please post the exact name of the Adobe program you use so a Moderator may move this message to that forum

Known Participant
May 22, 2020

Oh, sorry, I have just signed up to Adobe DC standard.