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

javascript to select field from dropdown list?

Community Beginner ,
Aug 02, 2017 Aug 02, 2017

asking if a javascript can be written to unhide and select a field based on a selection from a dropdown list?

TOPICS
PDF forms
8.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
1 ACCEPTED SOLUTION
Community Expert ,
Aug 03, 2017 Aug 03, 2017

Yes, by using this code:

var otherField = this.getField("2nd Lock Template");

if (event.value=="Other (Complete Below)") {

    otherField.display = display.visible;

    otherField.readonly = false;

    otherField.setFocus();

} else {

    otherField.display = display.hidden;

    otherField.readonly = true;

    otherField.value = "";

}

By the way, I noticed that in your code there are various problems. Do not use Word for editing code! Only use a plain-text editor, like Notepad.

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 ,
Aug 02, 2017 Aug 02, 2017

JavaScript can "unhide" a field, yes, but I'm not sure what you mean by "select" it... Please clarify.

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 ,
Aug 02, 2017 Aug 02, 2017

I have several dropdown lists on my form, for some of the selections I would like to have another field unhide so the operator can type in some information. However most of the answers do not require operator information so I don’t want the hidden field to show if those answers are 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
Community Expert ,
Aug 02, 2017 Aug 02, 2017

So the visibility of this field should be dependent on the value of multiple fields? That's a bit tricky... Under what circumstances should the field be visible then?

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 ,
Aug 02, 2017 Aug 02, 2017

The list will contain standard choices, but one choice will be “Other”. If that choice is selected then I want the control to go to another text field that the operator can type in their answer. So for instance there will be 5 standard choices and one that is “Other”. When a standard choice is selected we’ll go to the next item, when “Other” is selected we’ll unhide a text field and send control there.

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 ,
Aug 02, 2017 Aug 02, 2017

OK, that's more clear. As the custom Validation script of the drop-down field enter this code:

var otherField = this.getField("OtherText");

if (event.value=="Other") {

    otherField.readonly = false;

    otherField.setFocus();

} else {

    otherField.readonly = true;

    otherField.value = "";
}

Adjust the field name in the code as required, and make sure to tick the option to commit the selected value of the drop-down field immediately, under its Properties - Options tab.

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 ,
Aug 03, 2017 Aug 03, 2017

I used the following code:

Var otherField = this.getField(“2nd Lock Template”);

If (event.value==”Other (Complete Below)” {

otherField.readonly = false

otherField.setFocus();}

else

otherField.readonly = true

otherField.value = “”;}

Is there any way I can keep “2nd Lock Template” hidden and unhide in this code?

Thanks

Tom

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 ,
Aug 03, 2017 Aug 03, 2017

Yes, by using this code:

var otherField = this.getField("2nd Lock Template");

if (event.value=="Other (Complete Below)") {

    otherField.display = display.visible;

    otherField.readonly = false;

    otherField.setFocus();

} else {

    otherField.display = display.hidden;

    otherField.readonly = true;

    otherField.value = "";

}

By the way, I noticed that in your code there are various problems. Do not use Word for editing code! Only use a plain-text editor, like Notepad.

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 ,
Aug 03, 2017 Aug 03, 2017
LATEST

That’s working fine. Thanks for the help. Also, I entered the code using Adobe.

Tom

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