Expand my Community achievements bar.

Problem getting checkbox to make text field visible

Avatar

Former Community Member
I've searched the site and tried to get this to work on my own but I think I'm missing something important...

I have a checkbox named OtherParticipant and when it is checked I want my text field named OtherSiteName to be visible. This is my code for the checkbox, but it doesn't work. The text field is always visible.

I really appreciate your help.
















No






Yes
No





15 Replies

Avatar

Former Community Member
Hi Debra. I think you'd have an easier time of it if you were to make the text field invisible under Object >> Field >> Presence and then use the script editor to insert a script into the click event of the checkbox to make the field visible after the user clicks the checkbox. Here's a sample script:



if (this.rawValue == 1) { //this stands for current checkbox

formname.subformname.TextFieldName.presence = "visible"; // makes your text field visible

}



Regards,

Dave

Avatar

Former Community Member
Dave,

Thanks for the quick response. I'm still doing something wrong though...

Here is how I changed my code:





But it still isn't working. I actually tried to take the IF off and just leave the event activity so no matter if the checkbox is checked or not, the field would become visible. But that isn't working either, so I'm wondering what I'm doing wrong.

Now, my field value, if on is YES and if off is NO, does that matter? I changed it from 1 and 0. I've tried it with YES in place of 1 but that didn't seem to help, either.

BTW -- I did verify that I've saved the form as a dynamic form.

Avatar

Former Community Member
I took a look at the XML source of my form, it looks like you're missing the script tags. I still think you'd be better off to use the script editor to place your code rather than editing the XML directly. That way, Designer will place the proper tags for you. Posted below is the XML code generated by Designer from my script:





As far as I know, you can change the on/off values to anything you like, I don't think it matters. I always use the 1/0 since it's the default and that way I can recycle scripts for future use without having to go in and change the on/off values.

Regards,
Dave

Avatar

Former Community Member
Dave,



Not to take up too much of your time...but:



I did not know about the Script Editor, found other documents on how to do the "hide the text field" and they pointed me to the actual XML source. Glad to know there is a less intrusive way.



That being said, I went back to a "clean" copy of my form and did the following:



1. Form Properties, Defaults, Default Language, JavaScript.

2. Form Properties, Defaults, Preview Type, Interactive Form.

3. File, Save As, Save as Type, Dynamic PDF Form File.

4. Body Page, OtherParticipate (this is my checkbox) went into the Script Editor window and added your code then clicked the Enter Script Source Changes.

5. Body Page, OtherSiteName (this is my text field) changed Presence to Invisible.

6. Saved again for safety.

7. Viewed form, still doesn't work.



It just can't be this hard...ugh! Am I missing something basic, or is it really this hard?



Thanks again, and again I appreciate your help.

- Debra

Avatar

Former Community Member
Ok, I did the same thing, just started with a blank form and put a checkbox and a textfield on it and inserted the script. I then had to name my subform (I named it subform), rename my textfield (the default was TextField1) and rename my form name (the default is form1) to reflect the path given in my script. You can change the names of the form and subform in the Hierarchy pane on the left side of your Designer window. If it's not there, go to Window and click Hierarchy to show the pane. You can also change the name of the text field there, but I find it easier to change individual field names in the Object >> Binding tab. Once the names match, the script will work (provided, of course, that the form is saved as dynamic).

I know it seems like a lot of work at first, but after a while you'll be renaming everything as soon as you begin a new form out of habit. I would suggest that whenever possible you use the default Adobe form/field names. That way, when you re-use scripts from one form to another you'll be able to do so with as little alteration as possible.



Regards,

Dave

Avatar

Former Community Member
Thanks again Dave,



It still isn't working. My form was already named form1, I renamed my subform to subform2 (it is the 2nd of 3 pages) and left my other fields named the way they were (I pull the data out of the completed forms by the field names for other uses -- so I need specific names for the fields). I twice verified that my names through the path are correct. Any way, after all that, the text field still won't show up when I click on the OtherParticipate checkbox. I think I'll create a blank form like you did and try the checkbox and textbox by themselves in an effort to figure this out. I'm hesitant to rename fields on my form or anything too drastic because my form is huge (3 pages and lots of checkboxes). I'd like to hide the text box but I'm just not sure what I'm not doing right or what I'm doing wrong. Thanks for your help. I'll let you know if I figure out anything else and please let me know if you have an epiphanies.



- Debra

Avatar

Former Community Member
I'm not sure why it's not working unless you still have yes/no for your on/off values; if you do, you'd probably need to enclose them in quotes for the script to work. For example:



if (this.rawValue == "yes") { //this stands for current checkbox

form1.subform2.OtherSiteName.presence = "visible"; // makes your text field visible

}



I tested this exact script on a new form with a checkbox and a text field set to invisible. I changed my subform name to subform2 and my text field name to OtherSiteName and changed the on/off values to yes/no and it works.



Just to be clear, there aren't any other subforms involved, right? If the text field is nested within a child subform you'd also need to include that subform in the pathway.



Regards,

Dave

Avatar

Former Community Member
Hi Dave,



I have 3 separate subforms (not nested in each other but following each other -- basically page 1, page 2, and page 3). The field I'm working on is located on subform2 (or page 2). On the Binding tab for the checkbox, I have ON value as YES and OFF value as NO. I had this.rawValue == 1 in the script but then I tried your script from above but still no luck...does nothing. I can check the box but it refuses to show me my text field. Gotta be something simple that I'm just missing. It is most likely some glaringly obvious problem that I just can't seem to see. So...I'm starting at the begining of the LiveCycle Designer Scripting Basics document and trying to figure out what I've done wrong. If your bored or just can't seem to let this go (as I am not able to)...I'll be glad to send you the form for your viewing enjoyment. If I do figure it out, I'll be sure to post it on this thread so you can know.



Thanks, Debra

Avatar

Former Community Member
Dave,



You are probably getting tired of hearing from me...but I think I'm on to something...not sure what but something.



I decided to make the text field visible first, then when the checkbox is clicked, remove it. I know, not very useful but it acutally was. See, my text field actually went away when I clicked the checkbox. Then the form went nuts...meaning the scroll bar when nearly to the top then to the middle and then the form flickered. After that victory I made the text field invisible again and changed the code to add the IF and ELSE back in, just to get a feel for what the heck isn't working. Here is what I put in the JavaScript:



if (this.rawValue == 0) {form1.subform2.OtherSiteName.presence = "invisible";} else {form1.subform2.OtherSiteName.presence = "visible";}



Guess what? The text field pops up after the form goes nuts again. Now, when I click on the checkbox again, it just makes the form go nuts, the text field stays. I have also tried the above code with "1" with "YES" with "ON" and nothing makes the field go away again. So...that seems to tell me that the form can't find the correct value I'm asking it for, it finds everything but YES, NO, 1, 0, ON, or OFF.



Any ideas?

Avatar

Former Community Member
One last thing... you're posting the script in the click event of the checkbox and you have JavaScript selected as the Language, correct?



And no, I hate leaving things go if they're not working :).

Avatar

Former Community Member
Ok, after reading your last post, please email me the form at allendavid@co.kane.il.us. Something's goofy here.

Avatar

Former Community Member
Dave helped me fix the form. His script below was the correct answer:



if (this.rawValue == "Yes") {form1.subform2.OtherSiteName.presence = "invisible";} else {form1.subform2.OtherSiteName.presence = "visible";}



My last problem had to do with the YES being in all caps instead of just the Y capitolized. The form works great now. Thanks DAVE!!!!

Avatar

Former Community Member
I have 9 checkboxes in a subform. <br /><br />I have a calculate script which is below<br /><br />var cautionArray= new Array (UNCL,ORCON,FOUO);<br /><br /> <br /><br />for (var i=0;i<cautionArray.length;i++){<br /><br /> if( (cinfo2.ORCON.rawValue ==1)|| ( (cinfo2.FOUO.rawValue ==1)|| ( (cinfo2.UNCL.rawValue ==1)|){<br /><br />this.text = cautionArray[i]+/;<br /><br />}<br /><br />}<br /><br /> <br /><br />I only get the value of the last field in the array to display.<br /><br />I would like it to print all the checkboxes that have been selected.<br /><br />Basically I want the checkbox values to display in the textfield in another subform. What am I doing wrong?

Avatar

Former Community Member
Debra,



Check that your script editor event is set to 'Javascript' and not 'Formcalc'.



Scott

Avatar

Former Community Member
Hi David



I want to show a drop down list box "list2" when I select "LC at Sight" in the first drop down list box "list1".



List2 is invisible when I run the form.



I am using livecycle ES 8.2



Please help how can I do that..



kind regards

Asim