Skip to main content
Known Participant
May 18, 2021
Answered

Fields become required ONLY after selecting a radio button or checkbox

  • May 18, 2021
  • 11 replies
  • 3389 views

Please, help with script : Fields become required ONLY after selecting a radio button or checkbox (in this example -  "Other Country (please specify)").

 

Sample file in attachment.

 

Thanks.

This topic is closed to new replies. Start a new post to keep the conversation going.
Correct answer try67

if (this.getField("Registered In").valueAsString=="0") event.value = event.target.defaultValue;

 

Can you add more to this code to make the drop-down menu hidden again?

 

Thank you.


Use this as the whole code:

 

if (this.getField("Registered In").valueAsString=="1") {
	event.target.required = true;
	event.target.display = display.visible;
} else {
	event.target.required = false;
	event.target.display = display.hidden;
	event.value = event.target.defaultValue;
}

11 replies

try67
Community Expert
Community Expert
May 18, 2021

As the custom calculation script of the drop-down field enter the following:

event.target.required = this.getField("Registered In").valueAsString=="1";

Known Participant
May 18, 2021

Thank you. Works.

 

P.S. Is it possible to return the data from the drop-down menu (default) if you select the “Same” button after selecting “Different country (specify)” and choosing from the drop-down menu? A person can make a mistake when filling out.

try67
Community Expert
Community Expert
May 18, 2021

Sure. Add this line to that code:

if (this.getField("Registered In").valueAsString=="0") event.value = event.target.defaultValue;

Known Participant
May 18, 2021

Update attachment...