Skip to main content
Participant
March 27, 2024
Answered

Make text fields read only based on content selected in a drop down

  • March 27, 2024
  • 1 reply
  • 1688 views

I have a form on which I want to make some text fields Read-Only if a certain value is selected in the drop down menu of another field. I've tried:

if (this.getField("Combo Box 9").valueAsString = "Reprint") {

    this.getField("Text Field 42").readonly = true;

    }

Somehow the field becomes read-only by default then. 

This topic has been closed for replies.
Correct answer Thom Parker

So the code only changes the field to ReadOnly, not back, but it also contains an error.  The code below fixes the issue. 

But, since you've been trying different variations of code you may have bad code lying about in the form. Make sure all of the test code is removed. Then use this script in the "Validation" script for the "Combo Box 9" field, which is where this kind of script is supposed to go:

 

this.getField("Text Field 42").readonly = (event.value == "Reprint") ;

 

 

 

1 reply

Participant
March 27, 2024

For clarity, I've been trying a few things. I have the following as a custom format in the field I want to be readonly:

if (this.getField("eSample").item = "Reprint") {
this.getField("CoreColor").readonly = true;
}

That made the CoreColor field readonly immediately (regardless of the value in eSample). It seems like  my condition isn't being read, but the action is executed anyway. 

Nesa Nurani
Community Expert
Community Expert
March 27, 2024

When comparing, use double equal signs:

if (this.getField("eSample").item == "Reprint") {