These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Populate text field when checkbox is checked

BrianG
Registered: Dec 9 2011
Posts: 4
Answered

I'm a novice user of Adobe Acrobat 9. I've create a form consisting of an information page (Page 1) and a form document (Page 2) with text fields and checkboxes. One of the text fields is named "Name1". I will fill in the "Name1" text field with an individual's name. In the form document, I have another text field named "Name2" and two checkboxes next to it - named "Checkbox Yes" and "Checkbox No". If "Checkbox Yes" is checked, I would like "Name2" to be populated with the name which was filled into "Name1". If "Checkbox No" is checked, I would like "Name2" to be blank.
 
Any help would be appreciated.

My Product Information:
Acrobat Standard 9.4.3, Windows
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Do you want the user to be able to edit Name2 if the No checkbox is ticked?
Also, you should use radio-buttons, not check-boxes. They are a better suit for this situation. Or at least give the check-boxes the same name (but different export values) so they can't both be ticked at the same time.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

BrianG
Registered: Dec 9 2011
Posts: 4
I do not want the user to edit Name2 if the No checkbox is not ticked. The Name2 field would remain blank.
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Accepted Answer
OK. Then give both check-boxes the same name (let's say it's "CheckBox1"), and give one of them an export value of Yes and the other of No.
Then use this code as the custom calculation code for Name2:

event.value = (getField("CheckBox1").value=="Yes") ? getField("Name1").value : "";

Edit: code fixed.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

BrianG
Registered: Dec 9 2011
Posts: 4
If I enter the code in the Custom calculation script box, I get the following error message: SyntaxError missing ; before statement 1: at line 2

and it won't accept it.

I can enter the code in the Simplified field notation box and it is accepted, but it doesn't work,
try67
Expert
Registered: Oct 30 2008
Posts: 2398
(see above...)

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

BrianG
Registered: Dec 9 2011
Posts: 4
That did the trick. Thank you so much.