These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Binding selected checkbox field names to a text box

RichLorn
Registered: May 19 2008
Posts: 46

I'm trying to find the correct code which will write selected check box field names to a text box in a LiveCyle form. I've taken the javascript course at W3Schools.com, but it is a very basic course designed for HTML applications. I'm thinking that what I need is some use of the click event and getElementsByName(id)function but I've been unable after many tries to make it work at all.
 
My form consists of a number of check boxes on page 1 we can say are labeled answer1 thru answer5 in their respective field names. Upon the user selecting boxes, for example, answer1, answer3 and answer4, a target text box on page two will list the correcponding field names of each checkbox.
 
I'd like to use a button labeled "Update" at the bottom of the page 1 checkbox list which will initiate an event to first clear the page 2 text box of previous entries (if any) before populating it with all the new selected entries from page 1.
 
I hope someone can help me out. If this question has been answered already I apologize. I went back through old posts pretty far and didn't see any. Thanks.

My Product Information:
LiveCycle Designer, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
First, getElementsByName is a function of the HTML JavaScript DOM. It is not part of either the Acrobat or LiveCycle scripting DOM. One of the first things you need to do is to download the "Adobe XML Form Object Model Reference", which is basically the DOM reference for LiveCycle forms.

Next, you should get some LiveCycle and Acrobat specific JavaScript training. You'll find videos and articles on this site as well as www.pdfscripting.com
Here's a good one:
http://adobechats.adobe.acrobat.com/p87746471/

Now, there are few different techniques for approaching this problem. But the easiest and most straight forward is to just write a series of "if" statements that test the check boxes. The code can be placed on the click event of your update button, or it could be placed on the calculate event of the text field where the list of check boxes is displayed.

MycheckSummary.rawValue = ""; // Clear summary of check boxes
if(MyCheck1.rawValue == "1")
MycheckSummary.rawValue += "MyCheck1, ";

if(MyCheck2.rawValue == "1")
MycheckSummary.rawValue += "MyCheck2, ";


A more sophisticated and generalized technique would be to name/structure the checkboxes in such a way that they could be collected by the resolveNodes() function.



Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

RichLorn
Registered: May 19 2008
Posts: 46
As usual Thom, your posts are clear and thorough. Thank you!

I've located and downloaded the XML Form Object Model Reference, and I'll probably be watching your adobechat session more than once. I see I have some homework to do. Javascript applications from HTML to Livecycle aren't as straightforward as I hoped. But I have a comfortable chair and lots of strong coffee to energize my aging gray cells. :)