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

Activate a row of text boxes - Javascript

Engaged ,
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

1.4K

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

Community Expert , 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;
}

Votes

Translate

Translate
Community Expert , 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?

Votes

Translate

Translate
Engaged ,
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

Votes

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.

Votes

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
Engaged ,
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.

Votes

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
Community Expert ,
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?

Votes

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

Copy link to clipboard

Copied

Each drop down controls the text field below it.

Votes

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
Community Expert ,
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;
}

Votes

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
Engaged ,
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'.

Votes

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
Community Expert ,
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?

Votes

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
Engaged ,
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.

Votes

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
Engaged ,
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?

Votes

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

Copy link to clipboard

Copied

You can use the same name for this.

Votes

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.

Votes

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
Community Expert ,
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 ];}

Votes

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