Checking a checkbox based off of 4 independent fields

Explorer ,
Aug 13, 2018

Copy link to clipboard

Copied

I have a form that currently has 4 mapped fields that come over from our core.  Each of these fields is independent to an applicant (up to 4 applicants) and carries a unique value of "Y" or "N" or "U" based off of the applicants MLA status.  I would like my checkbox named "MLA" to check itself if ANY of those are Y, regardless if one is Y and the others are N, and regardless of the order they are answered, as they come through automatically so I have 0 idea which one gets there first.

I wrote the following script (with some help from a pro) and I still cannot get it to work.  I am a noob and am trying to teach myself, digging through forums and w3 schools and stackoverflow, so please take it easy on me:)  Any help is appreciated!!

var prompt = this.getField("APPLICANT_1_MLA_STATUS");

var prompt2 = this.getField("APPLICANT_2_MLA_STATUS");

var prompt3 = this.getField("APPLICANT_3_MLA_STATUS");

var prompt4 = this.getField("APPLICANT_4_MLA_STATUS");

var checkBox = this.getField("MLA");

var fieldArr = [ prompt, prompt2, prompt3, prompt4 ];

var currentVal = false;

for (var i = 0; i < fieldArr.length;i++) {

if (fieldArr == "Y" || fieldArr == "y") {

    currentVal.value = true;

  }

}

checkBox.checkThisBox(0, currentVal);

TOPICS
Acrobat SDK and JavaScript, Windows

Views

175

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

Checking a checkbox based off of 4 independent fields

Explorer ,
Aug 13, 2018

Copy link to clipboard

Copied

I have a form that currently has 4 mapped fields that come over from our core.  Each of these fields is independent to an applicant (up to 4 applicants) and carries a unique value of "Y" or "N" or "U" based off of the applicants MLA status.  I would like my checkbox named "MLA" to check itself if ANY of those are Y, regardless if one is Y and the others are N, and regardless of the order they are answered, as they come through automatically so I have 0 idea which one gets there first.

I wrote the following script (with some help from a pro) and I still cannot get it to work.  I am a noob and am trying to teach myself, digging through forums and w3 schools and stackoverflow, so please take it easy on me:)  Any help is appreciated!!

var prompt = this.getField("APPLICANT_1_MLA_STATUS");

var prompt2 = this.getField("APPLICANT_2_MLA_STATUS");

var prompt3 = this.getField("APPLICANT_3_MLA_STATUS");

var prompt4 = this.getField("APPLICANT_4_MLA_STATUS");

var checkBox = this.getField("MLA");

var fieldArr = [ prompt, prompt2, prompt3, prompt4 ];

var currentVal = false;

for (var i = 0; i < fieldArr.length;i++) {

if (fieldArr == "Y" || fieldArr == "y") {

    currentVal.value = true;

  }

}

checkBox.checkThisBox(0, currentVal);

TOPICS
Acrobat SDK and JavaScript, Windows

Views

176

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
Aug 13, 2018 0
Adobe Community Professional ,
Aug 13, 2018

Copy link to clipboard

Copied

Change that if statement block to:

if (fieldArr.value == "Y" || fieldArr.value == "y") {

    currentVal = true;

    break;  // No need to continue the loop since we found a 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
Reply
Loading...
Aug 13, 2018 0
Explorer ,
Aug 13, 2018

Copy link to clipboard

Copied

Hi George!

Thank you for the quick answer.  I tried it and it didn't work, but I may be misunderstanding.  I added it to the end so now my whole script looks like this...What am I missing?

var prompt = this.getField("APPLICANT_1_MLA_STATUS");

var prompt2 = this.getField("APPLICANT_2_MLA_STATUS");

var prompt3 = this.getField("APPLICANT_3_MLA_STATUS");

var prompt4 = this.getField("APPLICANT_4_MLA_STATUS");

var checkBox = this.getField("MLA");

var fieldArr = [ prompt, prompt2, prompt3, prompt4 ];

var currentVal = false;

for (var i = 0; i < fieldArr.length;i++) {

if (fieldArr == "Y" || fieldArr == "y") {

    currentVal.value = true;

    break;  // No need to continue the loop since we found a Yes

  }

}

checkBox.checkThisBox(0, currentVal);

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
Reply
Loading...
Aug 13, 2018 0
Adobe Community Professional ,
Aug 13, 2018

Copy link to clipboard

Copied

It doesn't look like anything has changed. This is what the entire script should look like:

var prompt = this.getField("APPLICANT_1_MLA_STATUS");

var prompt2 = this.getField("APPLICANT_2_MLA_STATUS");

var prompt3 = this.getField("APPLICANT_3_MLA_STATUS");

var prompt4 = this.getField("APPLICANT_4_MLA_STATUS");

var checkBox = this.getField("MLA");

var fieldArr = [prompt, prompt2, prompt3, prompt4];

var currentVal = false;

for (var i = 0; i < fieldArr.length; i++) {

    if (fieldArr.value == "Y" || fieldArr.value == "y") {

        currentVal = true;

        break;  // No need to continue the loop since we found a Yes

    }

}

checkBox.checkThisBox(0, currentVal);

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
Reply
Loading...
Aug 13, 2018 0
Explorer ,
Aug 14, 2018

Copy link to clipboard

Copied

Hi George,

I tried it exactly as you posted and it still wont work.  I'm wondering if I need to start from scratch?  Maybe an or statement would be better?

Thanks!

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
Reply
Loading...
Aug 14, 2018 0
Adobe Community Professional ,
Aug 14, 2018

Copy link to clipboard

Copied

Where exactly did you place this code?

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
Reply
Loading...
Aug 14, 2018 0