Skip to main content
Known Participant
December 11, 2017
Answered

Javascript modification?

  • December 11, 2017
  • 2 replies
  • 1393 views

I have 3 drop downs and I'm using this script to make them readonly and not,

if (event.value == "")

{

this.getField("TranChec").readonly = true;

this.getField("Tran1Htb").readonly = true;

this.getField("width").readonly = true;

this.getField("TranChec").value = "Off";

this.resetForm(["Text2bbb","Text22b"]);

}

if (event.value == "1")

{

this.getField("TranChec").readonly = false;

this.getField("Tran1Htb").readonly = false;

this.getField("width").readonly = false;

}

else if (event.value == "2")

{

this.getField("TranChec").readonly = false;

this.getField("Tran1Htb").readonly = false;

this.getField("width").readonly = false;

}

//the script goes up to 50.

What I would like to do is to eliminate all this script because at times I have to enter a number above 50 in the first drop down. At the moment when I enter a number higher than 50 the other two drop downs remain readonly. So, I'd like to be able to enter any number and the other two drop downs will become accessible and will become readonly on reset. Can someone help me with this problem and tell me how to modify this script? Thanks guys.

This topic has been closed for replies.
Correct answer try67

There's no need to repeat the same if-condition. Use this instead:

if (event.value >= 1) {

    this.getField("TranChec").readonly = false;

    this.getField("Tran1Htb").readonly = false;

    this.getField("width").readonly = false;

} else {

    this.getField("TranChec").readonly = true;

    this.getField("Tran1Htb").readonly = true;

    this.getField("width").readonly = true;

}

2 replies

Legend
December 11, 2017

So there is no difference at all between what you want to do when 1 is entered, or 2 or 3 or 50 or 76?

pdfUser1Author
Known Participant
December 11, 2017

Right. So, I found this script,

if (event.value >= 1) (this.getField("TranChec").readonly = false);

else (this.getField("TranChec").readonly = true);

if (event.value >= 1) (this.getField("Tran1Htb").readonly = false);

else (this.getField("Tran1Htb").readonly = true);

if (event.value >= 1) (this.getField("width").readonly = false);

else (this.getField("width").readonly = true);

this seems to work. I placed it into the Validate window of the first drop down and it makes them readonly when I reset and accessible when I select a number (1 or greater). I just have to play around with it a little. But, thanks for your time.

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
December 11, 2017

There's no need to repeat the same if-condition. Use this instead:

if (event.value >= 1) {

    this.getField("TranChec").readonly = false;

    this.getField("Tran1Htb").readonly = false;

    this.getField("width").readonly = false;

} else {

    this.getField("TranChec").readonly = true;

    this.getField("Tran1Htb").readonly = true;

    this.getField("width").readonly = true;

}

Legend
December 11, 2017

Are you wanting to do exactly the same thing for every case where event.value is not blank? Or only the cases where it is a positive number (more than zero)?

pdfUser1Author
Known Participant
December 11, 2017

well, the main drop down has just numbers. The first option is blank. The second option is "1", the third option is "2", etc. At the moment I have a list of 50. The sample script I provided goes up to 50. The problem is, if I enter a number above 50 the other two drop downs remain readonly. Kinda limits me to only 50. I don't want have to create a long list of 1000 options to be able to make the two drop downs accessible.

What I'm trying to do, (if it possible) is to be able to make the second and third drop down readonly when I reset the first drop down but to make the two other drop downs accessible when I enter ANY number in the first one. I hope that explains it enough. I thought the sample script above would.