• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Make text box disappear if not checked off

New Here ,
Apr 10, 2018 Apr 10, 2018

Copy link to clipboard

Copied

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?

TOPICS
Acrobat SDK and JavaScript , Windows

Views

637

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Apr 15, 2018 Apr 15, 2018

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"

...

Votes

Translate

Translate
Community Expert ,
Apr 10, 2018 Apr 10, 2018

Copy link to clipboard

Copied

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 PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 10, 2018 Apr 10, 2018

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 10, 2018 Apr 10, 2018

Copy link to clipboard

Copied

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

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 15, 2018 Apr 15, 2018

Copy link to clipboard

Copied

Lets say I have the following check boxes, text fields, default values:

Check Box110 ​ Text111 CVA

Check Box7c Text 27 HTN

Check Box7d Text 28 IDDM

(There are about 50 of these Check/box:Text filed combinations and I would

rather not rename them if I do not have to).

So it sounds like a create a master check box, under actions, mouse up,

run a java script:

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;});}

How do I specify the specific checkbox text :field combinations listed

above in your code? Thank you.

On Tue, Apr 10, 2018 at 6:08 PM, Terek, Richard <richard_terek@brown.edu>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 15, 2018 Apr 15, 2018

Copy link to clipboard

Copied

No, you can't use the code Thom provided with your naming "scheme". You would need to hard-code the names of all the fields into your code.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 15, 2018 Apr 15, 2018

Copy link to clipboard

Copied

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 ...

}

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 15, 2018 Apr 15, 2018

Copy link to clipboard

Copied

That works, although if I do not check the box, click the master box, text

disappears. If I uncheck the master, then check the box, then check the

master, text does not return. Anyway to make that happen?

Rick​

On Sun, Apr 15, 2018 at 5:45 PM, Thom Parker <forums_noreply@adobe.com>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 17, 2018 Apr 17, 2018

Copy link to clipboard

Copied

LATEST

That works, although if I do not check the box associated with the

text field, click the master box, text disappears. If I uncheck the

master, then check the box associated with the text field, then check

the master, text does not return. Anyway to make that happen?

Any thoughts on this?

Rick

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines