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

Creating Checkboxes and Text Field Dependency

Community Beginner ,
Mar 03, 2021 Mar 03, 2021

I have a couple of checkboxes - "Yes" and "No" - and a text field that follows.

 

I'd like to make the text field inactive if the "No" checkbox is checked, but make it active & required if the "Yes" checkbox is selected.

 

Is there a script that can generatre this kind of dependency?

 

(btw, I'm aware that a toggle button would be more funcionally appropriate than 2 independent checkboxes for the "yes" and "no", however I'm working with a fixed PDF template and the checkboxes fit better in that particular context).

 

Thanks!

TOPICS
How to , JavaScript , PDF forms
2.0K
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 ,
Mar 04, 2021 Mar 04, 2021

What are the names of the fields?

 

And there's no built-in toggle button in PDF forms, so you're good...

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 ,
Mar 04, 2021 Mar 04, 2021

Edit the name of the text field and use this script as a mouse up action in both radio-buttons:

 

var oFld = this.getField("nameOfTextField");
if (event.target.value == "Yes") {
oFld.readonly = false;
oFld.required = true;
}
else {
oFld.readonly = true;
oFld.required = false;
}

 


Acrobate du PDF, InDesigner et Photoshopographe
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 Beginner ,
Mar 04, 2021 Mar 04, 2021

Thanks, but not sure I follow your reply as I don't have a togle buttons but checkboxes:

 

I have 2 checkboxes (one named "no_checkbox" and the other "yes_checkbox") and I'd like the text field ("details_text") to become active and required if the "yes_checkbox" is ticked.

 

Is it possible to amend the suggested script to accomodate this setup?

 

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 Beginner ,
Mar 04, 2021 Mar 04, 2021

Thanks, I can name the elements any way I like, so say:

"no_checkbox"

"yes_checkbox"

"details_text"

(the idea is to have a yes/no question, and if the answer is "yes" to ask for further details in the text line)

Does this help?

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 ,
Mar 04, 2021 Mar 04, 2021

It's better to give the check-boxes the same name, so they can't be selected at the same time. Just give them unique export values, like "Yes" and "No". Let's say they are called "Checkbox1". You can then use this tool as the custom calculation script of the text field:

 

var v = (this.getField("Checkbox1").valueAsString=="Yes");
event.target.readonly = !v;

event.target.required = v;

if (!v) event.value = "";

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 Beginner ,
Mar 04, 2021 Mar 04, 2021

Thank you for this!

 

Just to clarify, what do I need to name the text field? (I'm not quite sure I understand how this script for the checkboxes ties in with the text field)

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 Beginner ,
Mar 04, 2021 Mar 04, 2021

Sorry, re-read your answer and realized this is the script for the text field! Sorry!

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 Beginner ,
Mar 04, 2021 Mar 04, 2021

Will try!

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 ,
Mar 04, 2021 Mar 04, 2021
LATEST

The name of the text field doesn't matter.

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