Highlighted

JavaScript check box state: if/else

Avatar

Guest

23-07-2008

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

Replies

Highlighted

pmcalex

24-07-2008

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!!
Highlighted

Avatar

Guest

24-07-2008

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
Highlighted

Avatar

Guest

15-08-2008

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