Skip to main content
Participant
July 19, 2023
Question

PDF form checkbox to duplicate one field in another

  • July 19, 2023
  • 1 reply
  • 410 views

Need a little assistance please - I have Checkbox1 that when it is checked populates the field Extra with the data from the field UnitSize and if it is not checked, leave the field Extra blank...or I guess when it toggles off and on to populate or clear the field Extra.  I would appreciate any help - new to this...Thanks K

This topic has been closed for replies.

1 reply

Thom Parker
Community Expert
Community Expert
July 19, 2023

Put this code in the MouseUp action for "Checkbox1"

this.getField("Extra").value = (event.value=="Off")?"":this.getField("UnitSize").value;

 

This populates or clears "Extra" only when the checkbox is clicked. If 
"Extra" needs to be updated whenever "UnitSize" is updated, then use this script in the custom calculation for "Extra"

event.value = (this.getField("Checkbox1").value=="Off")?"":this.getField("UnitSize").value;

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
expogalAuthor
Participant
July 19, 2023

ok - this is the error I get when I implement the above...

TypeError: this.getField(...) is null
1:AcroForm:Extra:Calculate
TypeError: this.getField(...) is null
1:AcroForm:Check Box1:Annot1:MouseUp:Action1

Thom Parker
Community Expert
Community Expert
July 19, 2023

The field names used in "this.getField" must exactly match the names of the fields on the form. 

Correct the names and the error will go away. 

 

Also, only use one of the solutions I provided. Do not use both on the form at the same time. 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often