Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


Activate a row of text boxes - Javascript

Explorer ,
Feb 18, 2021 Feb 18, 2021

Copy link to clipboard

Copied

Hello

I'd like to grey out a row of boxes so they are inactive.

 

If the user selects 'other' from a dropdown box then the row of boxes become 'active', white in colour with black text.

Question.jpg

TOPICS
JavaScript, PDF forms

Views

698

Likes

Translate

Translate

Report

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

correct answers 2 Correct answers

Adobe Community Professional , Feb 18, 2021 Feb 18, 2021
Then you can use the following as the custom validation script of each of the drop-down fields: var f = this.getField(event.target.name.replace("lms_antennatype_", "lms_antennatype_other_")); if (event.value=="Other") { f.readonly = false; } else { f.value = ""; f.readonly = true; }

Likes

Translate

Translate
Adobe Community Professional , Feb 19, 2021 Feb 19, 2021
You have to set the fields as read-only by default. I don't understand what you mean about the "select one" option. Do you want the text fields to be enabled when it is selected?

Likes

Translate

Translate
Explorer ,
Feb 18, 2021 Feb 18, 2021

Copy link to clipboard

Copied

Below are the backend names for the fields.

 

Screenshot 2021-02-18 at 10.24.52.png

Likes

Translate

Translate

Report

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
LEGEND ,
Feb 18, 2021 Feb 18, 2021

Copy link to clipboard

Copied

There are no "rows" in PDF forms, just independent form fields. Since you control the field names, you can create routines that work on groups of fields, by using rules in your own code for field names.

Likes

Translate

Translate

Report

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
Explorer ,
Feb 18, 2021 Feb 18, 2021

Copy link to clipboard

Copied

Sorry. 

The question was worded wrongly.

How do i activate a text box based on what is selected in the drop down box?

The default is inactive. When they select 'other' then the text box is activated.

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Feb 18, 2021 Feb 18, 2021

Copy link to clipboard

Copied

So the first drop-down should control all the other text fields, or do you mean that each drop-down controls the text field below it?

Likes

Translate

Translate

Report

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
Explorer ,
Feb 18, 2021 Feb 18, 2021

Copy link to clipboard

Copied

Each drop down controls the text field below it.

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Feb 18, 2021 Feb 18, 2021

Copy link to clipboard

Copied

Then you can use the following as the custom validation script of each of the drop-down fields:

 

var f = this.getField(event.target.name.replace("lms_antennatype_", "lms_antennatype_other_"));
if (event.value=="Other") {
	f.readonly = false;
} else {
	f.value = "";
	f.readonly = true;
}

Likes

Translate

Translate

Report

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
Explorer ,
Feb 19, 2021 Feb 19, 2021

Copy link to clipboard

Copied

The above works only if i click the dropdown box and choose one of the options except 'select one'.

 

I can still type in the text field if:

I click the dropdown box and choose 'select one'.

I don't click the dropdown box and go directly to the text field.

 

I can not type in the text field if:

I click the dropdown box and choose one on the options apart from 'other' and 'select one'.

I choose one of the options and then change it to 'select one'.

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Feb 19, 2021 Feb 19, 2021

Copy link to clipboard

Copied

You have to set the fields as read-only by default.

I don't understand what you mean about the "select one" option. Do you want the text fields to be enabled when it is selected?

Likes

Translate

Translate

Report

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
Explorer ,
Feb 19, 2021 Feb 19, 2021

Copy link to clipboard

Copied

Setting text fields to read only solved the problem.

 

"select one' is set as the default option in the dropdown list.

Likes

Translate

Translate

Report

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
Explorer ,
May 07, 2021 May 07, 2021

Copy link to clipboard

Copied

Does the variable 'f' have to be a different name in each drop-down field?

 

Or can i have the same name?

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
May 07, 2021 May 07, 2021

Copy link to clipboard

Copied

You can use the same name for this.

Likes

Translate

Translate

Report

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
LEGEND ,
May 07, 2021 May 07, 2021

Copy link to clipboard

Copied

LATEST

You can use the same variable name f in the code for each field, so long as you don't try and use it for two different things at the same time.

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Feb 18, 2021 Feb 18, 2021

Copy link to clipboard

Copied

Use this code in each dropdown field as "Custom calculation script" and change "xx" with your field names for that row:

var f = ["xx","xx","xx","xx"];
for (var i in f) {
this.getField(f[i]).readonly = event.value == "other" ? false : true;
this.getField(f[i]).borderColor = event.value == "other" ? color.black : ["G",0.7 ];}

Likes

Translate

Translate

Report

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