Skip to main content
Participant
January 30, 2017
Question

Check boxes and Auto populating text boxes

  • January 30, 2017
  • 2 replies
  • 835 views

I have  a form in  Adobe acrobat where i have multiple checkboxes.  Is there a way that if multiple check boxes are checked, the first check shows up on the first text box, and the second check box shows up in the second text box and so on, but; if the first check box is blank, and the second one is checked, could the second check box populate to the first text box instead of the second text box and so on down the line of all checkboxes required to auto populate text?

// array of field names to use

var aFieldNames = new Array("cb1", "cb2", "cb3", "cb4", "cb5", "cb6", "cb7", "cb8", "cb9", "cb10", "cb11", "cb12", "cb13", "cb14", "cb15", "cb16", "cb17", "cb18", "cb19", "cb20", "cb21", "cb22", "cb23", "cb24", "cb25", "cb26", "cb27", "cb28", "cb29", "cb30", "cb31", "cb32", "cb33", "cb34", "cb35", "cb36");

// clear the result field

event.value = "";

// variable for testing the value of a single field

var cItem = "";

// array of values not equal to "Off"

var aValues = new Array();

// process each field name

for (i = 0; i < aFieldNames.length; i ++) {

// get i name's field value as a string

cItem = this.getField(aFieldNames).valueAsString;

// see if value not equal to "Off"

if(cItem != "Off") {

// add to array of non "Off" values

aValues[aValues.length] = cItem;

} // end not "Off" value

} // end loop names

// set field value

event.value = aValues.join(" - \n\n");

this is my coding right now, i can't figure out how to stop the array when a box is checked, then populate into the first open text box, and then start again after the checked check box.

This topic has been closed for replies.

2 replies

try67
Community Expert
Community Expert
January 30, 2017

Assuming you have at least as many text fields as check-boxes, and they're named "text1", "text2", etc., you can use this code to do it (place it as the custom calculation script of a separate, hidden text field):

var maxFields = 36;

var textFieldsCounter = 0;

for (var i=1; i<=maxFields; i++) {

    if (this.getField("cb"+i).value!="Off") {

        textFieldsCounter++;

        this.getField("text"+textFieldsCounter).value = this.getField("cb"+i).value;

    }

}

Participant
January 30, 2017

There are 36 text boxes, yes.  Thank you I will try this out.

Participant
January 30, 2017

Thanks for the help.  It worked.

try67
Community Expert
Community Expert
January 30, 2017

In the code above you're populating everything into a single field, which is not what you describe in your question. So which one is it?

Also, how many text fields are there?