Skip to main content
Participant
April 16, 2024
Answered

Javascript for text box to auto populate from a check box

  • April 16, 2024
  • 1 reply
  • 195 views

I have a form with a Yes check box and a No check box. 

When the user checks No, I would like the text box beside it to autopopulate to read "Not Applicable".

When the user checks Yes, I would like the text box to be free flow text entry.

I am stuck on the javascript to accomplish this. Also, does the script go into the properties of the checkbox or into the text box? 

Using Adobe Acrobat X Standard

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

To get started read this article:

https://www.pdfscripting.com/public/How-to-write-an-If-statement.cfm

 

Basically, you want to use the MouseUp action to run a script that will set the value of the text field when checked, and make it read only,  but when uncheck, clear the field and make it not readonly.

 

var oTxtFld = this.getFeild("TextField");

if(event.target.value == "Off")

{//Unchecked

     oTxtFld.readonly = false;

     oTxtFld.value = "";

}

else

{

     oTxtFld.readonly = true;

     oTxtFld.value = "Not Applicable";

}

 

      

1 reply

Thom Parker
Community Expert
Thom ParkerCommunity ExpertCorrect answer
Community Expert
April 16, 2024

To get started read this article:

https://www.pdfscripting.com/public/How-to-write-an-If-statement.cfm

 

Basically, you want to use the MouseUp action to run a script that will set the value of the text field when checked, and make it read only,  but when uncheck, clear the field and make it not readonly.

 

var oTxtFld = this.getFeild("TextField");

if(event.target.value == "Off")

{//Unchecked

     oTxtFld.readonly = false;

     oTxtFld.value = "";

}

else

{

     oTxtFld.readonly = true;

     oTxtFld.value = "Not Applicable";

}

 

      

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