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

Activate a row of text boxes - Javascript

Engaged ,
Feb 18, 2021 Feb 18, 2021

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.jpgexpand image

TOPICS
JavaScript , PDF forms
2.1K
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
2 ACCEPTED SOLUTIONS
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;
}

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

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

Below are the backend names for the fields.

 

Screenshot 2021-02-18 at 10.24.52.pngexpand image

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

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.

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

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.

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

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?

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

Each drop down controls the text field below it.

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 ,
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;
}
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
Engaged ,
Feb 19, 2021 Feb 19, 2021

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

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

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

Setting text fields to read only solved the problem.

 

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

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

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

 

Or can i have the same name?

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

You can use the same name for this.

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

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

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 ];}

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