Skip to main content
yanksgirl
Inspiring
August 13, 2018
Question

Checking a checkbox based off of 4 independent fields

  • August 13, 2018
  • 1 reply
  • 785 views

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

This topic has been closed for replies.

1 reply

Inspiring
August 13, 2018

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

}

yanksgirl
yanksgirlAuthor
Inspiring
August 13, 2018

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

Inspiring
August 13, 2018

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