Javascript modification?

Explorer ,
Dec 11, 2017

Copy link to clipboard

Copied

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.

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

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;

}

TOPICS
Acrobat SDK and JavaScript, Macintosh, Windows

Views

156

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Javascript modification?

Explorer ,
Dec 11, 2017

Copy link to clipboard

Copied

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.

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

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;

}

TOPICS
Acrobat SDK and JavaScript, Macintosh, Windows

Views

157

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Dec 11, 2017 0
Most Valuable Participant ,
Dec 11, 2017

Copy link to clipboard

Copied

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)?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 11, 2017 0
Explorer ,
Dec 11, 2017

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 11, 2017 0
Most Valuable Participant ,
Dec 11, 2017

Copy link to clipboard

Copied

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?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 11, 2017 0
Explorer ,
Dec 11, 2017

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 11, 2017 0
Most Valuable Participant ,
Dec 11, 2017

Copy link to clipboard

Copied

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;

}

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 11, 2017 0
Explorer ,
Dec 12, 2017

Copy link to clipboard

Copied

I see. Thanks for your help. The script works fine. I just don't know enough about script (but learning everyday) to know how to script it another way.

I also have to include a reset for certain fields. How would I include that? Where would it go?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 12, 2017 0
try67 LATEST
Most Valuable Participant ,
Dec 13, 2017

Copy link to clipboard

Copied

Where it would go depends on when you want to execute it, but the command is this:

this.resetForm(["Field1", "Field2", "Field3"]);

If you want to reset the entire file use this:

this.resetForm();

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 13, 2017 1