Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Why won't this script make the check box "read-only"?

Community Beginner ,
Dec 18, 2020 Dec 18, 2020

I have a script for a checkbox that when checked will check other checkboxes at once.  It is supposed to check all of the boxes and then make those checkboxes read-only, reverting back again if the original checkbox is then unchecked.

 

For some reason, the first check box (CheckBoxNA7.1) won't turn to read-only and I can't figure out why! I am only showing a portion of the script as the full script has 6 checkboxes and all the other 5 turns to read-only, just not 7.1 for some reason.  Can anybody see what the issue might be?

 

if(event.target.isBoxChecked(0)){

this.getField("CheckBoxNA7.1").checkThisBox(0,true);

this.getField("CheckBoxNA7.1").readonly = true;}

if(event.target.value != "Off"){

this.getField("Score7.1").value = "";

this.getField("CheckBoxD7.1").value = "Off";

this.getField("CheckBoxD7.1").readonly = true;

this.getField("CheckBoxNA7.2").checkThisBox(0,true);

this.getField("CheckBoxNA7.2").readonly = true;}

if(event.target.value != "Off"){

this.getField("Score7.2").value = "";

this.getField("CheckBoxD7.2").value = "Off";

this.getField("CheckBoxD7.2").readonly = true;

this.getField("CheckBoxO7.2").value = "Off";

this.getField("CheckBoxO7.2").readonly = true;}

else

this.getField("CheckBoxNA7.1").checkThisBox(0,false);

this.getField("CheckBoxNA7.1").readonly = false;

if(event.target.value == "Off"){

this.getField("Score7.1").value = 3;

this.getField("CheckBoxD7.1").readonly = false;

this.getField("CheckBoxNA7.2").checkThisBox(0,false);

this.getField("CheckBoxNA7.2").readonly = false;}

if(event.target.value == "Off"){

this.getField("Score7.2").value = 4;

this.getField("CheckBoxD7.2").readonly = false;

this.getField("CheckBoxO7.2").readonly = false;}

TOPICS
PDF forms
1.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
2 ACCEPTED SOLUTIONS
Community Expert ,
Dec 18, 2020 Dec 18, 2020

Check your { } constructs.

You set readonly of this field always to false.

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 18, 2020 Dec 18, 2020

In the first part of the code you're setting the field as read-only if the check-box is checked, but later on you're setting it as not read-only if it's not not checked... Confused? So am I... I suggest you work on your code and try to improve its clarify. Combine all the statements that should happen if the field is checked into one block, and all the ones for when it's not checked to another, and don't duplicate the conditions (with different syntax each time).

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 18, 2020 Dec 18, 2020

Check your { } constructs.

You set readonly of this field always to false.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 18, 2020 Dec 18, 2020

In the first part of the code you're setting the field as read-only if the check-box is checked, but later on you're setting it as not read-only if it's not not checked... Confused? So am I... I suggest you work on your code and try to improve its clarify. Combine all the statements that should happen if the field is checked into one block, and all the ones for when it's not checked to another, and don't duplicate the conditions (with different syntax each time).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 18, 2020 Dec 18, 2020

With your guidance, I got what I wanted with this:

if(event.target.isBoxChecked(0)){

this.getField("CheckBoxNA7.1").checkThisBox(0,true);

this.getField("CheckBoxNA7.1").readonly = true;

this.getField("CheckBoxNA7.2").checkThisBox(0,true);

this.getField("CheckBoxNA7.2").readonly = true;

this.getField("CheckBoxD7.1").value = "Off";

this.getField("CheckBoxD7.1").readonly = true;

this.getField("CheckBoxD7.2").value = "Off";

this.getField("CheckBoxD7.2").readonly = true;

this.getField("CheckBoxO7.2").value = "Off";

this.getField("CheckBoxO7.2").readonly = true;

if(event.target.value != "Off")

this.getField("Score7.1").value = "";

if(event.target.value != "Off")

this.getField("Score7.2").value = "";}

else{

this.getField("CheckBoxNA7.1").checkThisBox(0,false);

this.getField("CheckBoxNA7.1").readonly = false;

this.getField("CheckBoxNA7.2").checkThisBox(0,false);

this.getField("CheckBoxNA7.2").readonly = false;

this.getField("CheckBoxD7.1").readonly = false;

this.getField("CheckBoxD7.2").readonly = false;

this.getField("CheckBoxO7.2").readonly = false;

if(event.target.value == "Off")

this.getField("Score7.1").value = 3;

if(event.target.value == "Off")

this.getField("Score7.2").value = 4;}

Thank you very much

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 18, 2020 Dec 18, 2020
LATEST

Better, but not quite there yet... This is the only if statement you should have:

 

if (event.target.isBoxChecked(0)){

// put all the statements to execute if the check-box is ticked here

} else {

// put all the statements to execute if the check-box is NOT ticked here

}

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