Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

JavaScript check box state: if/else

Not applicable
Hi



I am trying to use JavaScript to read a check box's value, and, if it is "1" then make a text field visible (text field is initialized as presence = "invisible"), and if the check box's value = "0" then continue to keep the text filed box invisible.



The form is saved as a dynamic 8 XML pdf. The script for click of the check box is:



if (CheckBox1.rawValue = "1")

{

TextField1.presence = "visible"

}

else

(CheckBox1.rawValue = "0")

{

TextField1.presence = "invisible"

}



This works OK.



The problem: there are several check boxes, each of which, if checked, causes a single text field box to become visible. If the user unchecks one of these but leaves another checked, it should still display the text field box. But, unchecking any one of the check boxes, makes the text field box invisible. What the form needs is for the text field box to dispaly if any of the check boxes are checked.



I tried adding an "or" to the script with no success:



if (CheckBox1.rawValue = "1")|(CheckBox2.rawValue = "1")

{

TextField1.presence = "visible"

}

else

(CheckBox1.rawValue = "0")

{

TextField1.presence = "invisible"

}



If I add the | (CheckBox2.rawValue = "1"), the text box no longer displays when either check box1 or check box 2 are checked. Nothing works using this.



I've tried changing the values for each check box to other numbers (for example "2"). I've tried using == instead of =, and || instead of |. Nothing helps.



I must be doing something wrong in the script or setting.



I'm stuck and would appreciate any help.



Kind Regards,



Stephen
3 Replies
pmcalex
Level 2
Level 2
Try placing this in the change event of the checkbox:



if (this.rawValue == 1)

{

TextField1.presence = "visible";

}

else if (this.rawValue == 0)

{

TextField1.presence = "invisible";

}



Good luck!!
Not applicable
Hi Thank you for your reply and suggestion.



I made a change to allow for any of the 7 check boxes to be checked then unchecked and still show the text field box if even one remains checked:



//for check box 3

if (this.rawValue == 1)

{

TextField3.presence = "visible";

}

else if (CheckBox1.rawValue == 1)

{

TextField3.presence = "visible";

}

else if (CheckBox2.rawValue == 1)

{

TextField3.presence = "visible";

}

else if (CheckBox4.rawValue == 1)

{

TextField3.presence = "visible";

}

else if (CheckBox5.rawValue == 1)

{

TextField3.presence = "visible";

}

else if (CheckBox6.rawValue == 1)

{

TextField3.presence = "visible";

}

else if (CheckBox7.rawValue == 1)

{

TextField7.presence = "visible";

}

else if (this.rawValue == 0)

{

TextField3.presence = "invisible";

}



(the box numbers are varied depending on which check box change event is used)



This works well.



Again, thanks for your help.



Kind Regards,



Stephen
Not applicable
I am trying to hide chek boxs that are un-checked based on a switch of some kind.



the if statement in my mind should go



if this control field = true and this sub-field = false then subfield is hidden.



this has the effect I want on a single check box



if (this.xfa.event.change == true) {



numStateTaxRate.rawValue = 7.50;

}



else {



chkFederalTax.presence = "hidden";



}



but i want to expand it to hide other check boxs if they are unchecked



thank you as i have found many post very helpful