Skip to main content
tomw12849292
Known Participant
August 2, 2017
Answered

javascript to select field from dropdown list?

  • August 2, 2017
  • 1 reply
  • 8376 views

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

This topic has been closed for replies.
Correct answer try67

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


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.

1 reply

try67
Community Expert
Community Expert
August 2, 2017

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

tomw12849292
Known Participant
August 2, 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.

tomw12849292
Known Participant
August 2, 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?


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.