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.

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
August 3, 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


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.