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

Form Assistance: If any checkbox is checked, hidden text box turns on

New Here ,
Jun 21, 2024 Jun 21, 2024

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!

TOPICS
How to , JavaScript , PDF forms
495
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 ,
Jun 21, 2024 Jun 21, 2024
LATEST

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

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 ,
Jun 21, 2024 Jun 21, 2024
LATEST

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

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