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

Fields inactive until checkbox is checked

New Here ,
Oct 20, 2017 Oct 20, 2017

Looking for a way to keep a set of fields inactive (not fillable, read-only etc) until a single checkbox is checked. I have pretty much an entire page that does not need filled in unless someone would check a box for that option.

Thanks

TOPICS
PDF forms
1.4K
Translate
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
1 ACCEPTED SOLUTION
Community Expert ,
Oct 20, 2017 Oct 20, 2017

Use this code as the Mouse Up event of the check-box:

var fields = ["Field1", "Field2", "Field3"];

for (var i in fields) {

    var f = this.getField(fields);

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

        f.readonly = true;

        f.value = f.defaultValue;

    } else {

        f.readonly = false;

    }

}

  

Adjust the names of the fields in the first line to match those in your file, of course.

View solution in original post

Translate
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 ,
Oct 20, 2017 Oct 20, 2017

Use this code as the Mouse Up event of the check-box:

var fields = ["Field1", "Field2", "Field3"];

for (var i in fields) {

    var f = this.getField(fields);

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

        f.readonly = true;

        f.value = f.defaultValue;

    } else {

        f.readonly = false;

    }

}

  

Adjust the names of the fields in the first line to match those in your file, of course.

Translate
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 ,
Oct 20, 2017 Oct 20, 2017

Can't get that script to work. Any suggestions?

Translate
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
Engaged ,
Feb 18, 2021 Feb 18, 2021
LATEST

I've managed to understand the rest of the code except for one line.

 

What is 
for (var i in fields)

 

What does the 'i' refer to?

Translate
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 ,
Oct 20, 2017 Oct 20, 2017

Actually I just noticed it does work, but it's doing the opposite. Its only making them inactive when the box is UNchecked.

Translate
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 ,
Oct 20, 2017 Oct 20, 2017

Are you sure you placed it where I indicated?

Translate
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 ,
Oct 20, 2017 Oct 20, 2017

Yes, at least I think so...

Screen Shot 2017-10-20 at 1.20.08 PM.png

Translate
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 ,
Oct 20, 2017 Oct 20, 2017

Does the export value of the checkbox affect the script? Mine is set to YES

Translate
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 ,
Oct 20, 2017 Oct 20, 2017

Sorry, I misunderstood how you wanted it to work.

Simply change line #4 from:

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

to:

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

Translate
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 ,
Oct 20, 2017 Oct 20, 2017

try67...

This script was working till I added some additional field names to it. I'm getting the below error. Can you tell me what I need to do? I appreciate your help!

Screen Shot 2017-10-20 at 3.31.20 PM.png

Translate
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 ,
Oct 20, 2017 Oct 20, 2017

You probably missed a comma or something like that. Post the code as text, not as an image.

Translate
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 ,
Oct 20, 2017 Oct 20, 2017

Sorry. Think I found it. Missed a " mark.

Again, thank you for your assistance. Very helpful

Translate
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