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

Set textbox value based on multiple other form fields

Explorer ,
Jul 29, 2019 Jul 29, 2019

I am working on a form that has a required question with multiple choices. If any one of the choices is completed, the question is considered answered. I am attempting to create a hidden field that would work as the check to validate that the question was answered. I would also like if one of the multi-choice fields is cleared out that the hidden test field also clears out. The multiple choices consist of one checkbox and three text fields.

Could someone please assist in correcting ?

var a = this.getField("Checkbox1");

var b = this.getField("TextField1");

var c = this.getField("TextField2");

var d = this.getField("TextField3");

if (a.value=="On"){

  event.value = "On";

}

else if (a.value==""){

  event.value = "";

}

else if (b.value){

   (event.value = b.value);

}

else if (c.value){

   event.value = c.value;

}

else if (d.value){

   event.value = d.value;

}

else{

  event.value = "";

}

TOPICS
PDF forms
1.3K
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 ,
Jul 29, 2019 Jul 29, 2019

If I understood you correctly, you can try this:

var a = this.getField("Checkbox1").valueAsString;

var b = this.getField("TextField1").valueAsString;

var c = this.getField("TextField2").valueAsString;

var d = this.getField("TextField3").valueAsString;

if (a=="Off" || b=="" || c=="" || d=="") event.value = "";

else event.value = "OK";

The actual value of the field doesn't matter, as long as it's filled in, since it's hidden.

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 ,
Jul 29, 2019 Jul 29, 2019

If I understood you correctly, you can try this:

var a = this.getField("Checkbox1").valueAsString;

var b = this.getField("TextField1").valueAsString;

var c = this.getField("TextField2").valueAsString;

var d = this.getField("TextField3").valueAsString;

if (a=="Off" || b=="" || c=="" || d=="") event.value = "";

else event.value = "OK";

The actual value of the field doesn't matter, as long as it's filled in, since it's hidden.

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
Explorer ,
Jul 29, 2019 Jul 29, 2019

So close! But it looks like your script won't populate the target field unless ALL variables are completed. I need it populated with OK if one of the four are completed.

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 ,
Jul 29, 2019 Jul 29, 2019

Ah, OK. Then change all of the "||" to "&&" (no quotes).

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
Explorer ,
Jul 29, 2019 Jul 29, 2019
LATEST

THANK YOU! Works perfectly.

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