Fields inactive until checkbox is checked

New Here ,
Oct 20, 2017 Oct 20, 2017

Copy link to clipboard

Copied

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
Macintosh, PDF forms, Windows

Views

234

Likes

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

Most Valuable Participant , 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.

Likes

Translate

Translate
Most Valuable Participant ,
Oct 20, 2017 Oct 20, 2017

Copy link to clipboard

Copied

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.

Likes

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

Copy link to clipboard

Copied

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

Likes

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 Beginner ,
Feb 18, 2021 Feb 18, 2021

Copy link to clipboard

Copied

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?

Likes

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

Copy link to clipboard

Copied

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

Likes

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
Most Valuable Participant ,
Oct 20, 2017 Oct 20, 2017

Copy link to clipboard

Copied

Are you sure you placed it where I indicated?

Likes

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

Copy link to clipboard

Copied

Yes, at least I think so...

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

Likes

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

Copy link to clipboard

Copied

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

Likes

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
Most Valuable Participant ,
Oct 20, 2017 Oct 20, 2017

Copy link to clipboard

Copied

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") {

Likes

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

Copy link to clipboard

Copied

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

Likes

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
Most Valuable Participant ,
Oct 20, 2017 Oct 20, 2017

Copy link to clipboard

Copied

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

Likes

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

Copy link to clipboard

Copied

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

Again, thank you for your assistance. Very helpful

Likes

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