Copy link to clipboard
Copied
I am new to java script and have been trying to figure this out by reading multiple posts but I haven't found a solution that will work yet.
I am creating a form that has 15 questions, each with a Yes or No checkbox - each is labeled Yes.1 and No.1 with all outputs set to Yes. I am trying to write a script if any "No" checkbox is checked, a text box appears at the bottom that says "Rejected." I already have that box named "rejected" and figured out how to set the options so it is hidden and locked. I just cannot get it to appear if one of the "No" boxes is checked. To the text box I have added an action with Mouse Up to run a java script as follows:
event.target.hidden = !this.getField("No. ").getArray().some(function(a){return (a.value == "Yes")});
How far off am I? Any assistance is appreciated!
Copy link to clipboard
Copied
This is not a good setup. You should give each set of fields the same field name, but unique export values ("Yes" and "No", for example), to prevent both fields in a group from being selected at the same time.
Also, there are some issues with your code and how you're seeing it up. If you hide the field then clicking it won't be possible and you won't be able to make visible once more. Use the Calculation event of the field, instead.
Also, the "hidden" property is deprecated and should not be used. Use the display property instead.
So if your fields are named Q1 to Q15 with export values of "Yes" and "No" then you could use the following as the custom calculation script of your text field:
var bNoSelected = false;
for (var i=1; i<=15; i++) {
if (this.getField("Q"+i).valueAsString=="No") {
bNoSelected = true;
break;
}
}
event.target.display = (bNoSelected) ? display.visible : display.hidden;
The last line can also be replaced with:
event.value = (bNoSelected) ? "Rejected" : "";
Copy link to clipboard
Copied
This is not a good setup. You should give each set of fields the same field name, but unique export values ("Yes" and "No", for example), to prevent both fields in a group from being selected at the same time.
Also, there are some issues with your code and how you're seeing it up. If you hide the field then clicking it won't be possible and you won't be able to make visible once more. Use the Calculation event of the field, instead.
Also, the "hidden" property is deprecated and should not be used. Use the display property instead.
So if your fields are named Q1 to Q15 with export values of "Yes" and "No" then you could use the following as the custom calculation script of your text field:
var bNoSelected = false;
for (var i=1; i<=15; i++) {
if (this.getField("Q"+i).valueAsString=="No") {
bNoSelected = true;
break;
}
}
event.target.display = (bNoSelected) ? display.visible : display.hidden;
The last line can also be replaced with:
event.value = (bNoSelected) ? "Rejected" : "";
Find more inspiration, events, and resources on the new Adobe Community
Explore Now