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

Hard Javascript Question

DJMP
Registered: Nov 14 2007
Posts: 5

I want to have 50 or so check boxes on page 2 and when any 1 of the 50 are checked off it populates text field 1 on page one with the text. When a second one is checked off i want it to populate text field 2 on page 1.

I'm thinking an if statement might work? I'm a beginner trying to do a job for work. So any help would be appreciated. Could it be fairly detailed due to me being a beginner. Thanks so much

Dave

gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
You will either have to code a very specific "If" statement for each check box.

If you understand field naming using hierarchical field names and how to use an array variable, you could name the check box, text field and place the text in an array that would be tied together by a common value. one could then extract the common value from the check box field and then be able to associate the text in an array element with the same common number to a text field with the same common number. For example the check boxes could be name "CheckBox.#" the text field associated with the check box would be named "Text.#" where "#" is the zero based value of the repeated field and you text would be placed into a zero based array where the "0" element value would be associated with he field "CheckBox.0" to be placed in the "Text.0" field. The script for the "Mouse Up" action for each check box could be:

var sField = event.target.name; // get the name of the check box
var aField = sField.split("."); // create an array of the field name splitting at the "."
var nField = aField[aField.length - 1]; // get the last element of the field's name
this.getField("Text." + nField).value = ""; // by default clear the field associated with the check box
// if field is checked
if (this.getField(event.target.name).value != "Off") {
this.getField("Text." + nField).value = aText[nField]; // get text associated with the check box field

You would need to initialize an array as document level variable with:

aText = new Array("Text for field 0",
"text for field 1",
"text for field 2",
"text for field n");

George Kaiser

DJMP
Registered: Nov 14 2007
Posts: 5
Could you simplify any?
richruiz
Registered: Dec 27 2007
Posts: 1
1. Give the two relate fields a common name such as ....

MyFields_1_chk and MyFields_1_txt
MyFields_2_chk and MyFields_2_txt
MyFields_3_chk and MyFields_3_txt

....and so on.


2. Assuming they reside in the subforms subCks and subTxt . Set the text field to be calculated. In its calulation script but the following code.....


var name = this.name;
// get the corresponding check box
var chkbox = xfa.resolveNode("subCks." + name.substring(0,name.lenght -3) + "chk" );
var ans = "";

// assuming you want the text to be the check box's label, return the label

if(chkbox.rawValue == 1) // or whatever the raw value is
ans = chkbox.caption.value.text.value;


This is not tested but sould work with a little tweeking

Rich Ruiz
Novanis
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
My example was for AcroForms not LiveCycle Designer.

The OP did not state which program is being used.

George Kaiser