Skip to main content
Cheena12
Inspiring
July 29, 2019
Answered

Set textbox value based on multiple other form fields

  • July 29, 2019
  • 1 reply
  • 1302 views

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 = "";

}

This topic has been closed for replies.
Correct answer try67

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.

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
July 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.

Cheena12
Cheena12Author
Inspiring
July 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.

try67
Community Expert
Community Expert
July 29, 2019

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