Skip to main content
Participant
September 1, 2026
Question

How do I work with Javascript and Check Boxes?

  • September 1, 2026
  • 2 replies
  • 19 views

I’m completely lost.  

 

I am working on a form that has several check boxes that I want to generate text based on whether the box is checked or not. 

 

Example:

A field named “form required” has a check box.  The text I want to generate is:

 

If the check box for “form required” is blank (false), the text output is:   “\nForm Required: No”

If the check box for “form required” is checked (true), the text output is:  “\nForm Required: Yes”

 

How can I do this in Javascript?   How do I get the value to update dynamically?

 

This code does not work:

if(this.getField(“form required”).value)
  event.value=”Form Required: Yes”;
else
  event.value=”Form Required: No”;

 

And I’m not sure how isboxchecked works either.  

 

Please advise.  Thank you.  

 

2 replies

Nesa Nurani
Community Expert
Community Expert
September 2, 2026

From your post I assume "form required" is text field name, so you can use this under checkbox action tab as Mouse UP action, select 'Run a JavaScript' and enter this script:


this.getField("form required").value = (event.target.value == "Off")? "No" : "Yes";

Thom Parker
Community Expert
Community Expert
September 2, 2026

Since the result of the checkbox action is displayed in a text box, the best place to put the script is in the calculation script for the text box.  I’m assuming this is what you’ve done given the code you’ve posted.  And this code is nearly complete, Just one step to go.

The value of a checkbox or radio button is either the export value or “Off”.  So the value in the “if” statement needs to be compared to one of these values. I’d suggest using “Off” since it is always valid.  Like this:

if(this.getField(“form required”).value != ”Off”)
  event.value=”Form Required: Yes”;
else
  event.value=”Form Required: No”;

 

However, there is another issue with this code, which is that (I think) the double quotes are wrong. They look like Unicode quotes, and they need to be ASCII quotes. You can tell if the code fails and throws an error, which can be seen in the console window.  

 

It might help for you to read this article: https://www.pdfscripting.com/public/PDF-Form-Scripting.cfm

 

 

 

 

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