Skip to main content
Participant
April 10, 2018
Answered

Make text box disappear if not checked off

  • April 10, 2018
  • 1 reply
  • 986 views

I have a form with multiple text boxes with default
text.  Next to each text box I have a check
box that starts out as not checked.  When I open the form I would like
to see the default text in all of the text boxes, check off the ones that apply
to a particular record, then have the default text disappear if not checked off
after saving the form.  Any way to do
this?

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

For any scheme to work the script has to have some way of relating the checkbox to the text field. This is done though either the field naming, or as Try67 has eloquently stated, by hard coding it in the script.  There is definitely an advantage to designing your scheme before making up the form.

There are a couple of different ways to proceed with a hard coding scheme.

Here's the easy one.

if(event.value != "Off")

{

   if(this.getField("Check Box110").value == "Off")

         this.getField("Text111").display = display.hidden;

.... Repeat for all the other field combinations ...

}

1 reply

Thom Parker
Community Expert
Community Expert
April 10, 2018

You'll need a checkbox that initiates the action that hides the unchecked fields.

The first part of this solution is to name the fields in such a way that the text field name can be easily derived from the associated checkbox name. For example "Check.Default1" and "Text.Default1".

The script gets all the checkbox fields in an array by using the name prefix. Then loops over the array to test the checkbox value and then hides the text field if it is unchecked.

Here's a portion of the script for the Master Checkbox.

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

{

     this.getField("Check").getArray().forEach(function(a){if(a.value=="Off") this.getField(a.name.replace(/Check/,"Text")).hidden = true;});

}

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Participant
April 10, 2018

I see the logic.

What is the rest of the java script and where do I put it?

How do I designate a master checkbox?

Many thanks.

Rick

Thom Parker
Community Expert
Community Expert
April 10, 2018

That's the whole thing and it goes in the MouseUp event.

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