Copy link to clipboard
Copied
Do I do this in InDesign or Acrobat?
I have 5 checkboxes as possible answers to a question and want to have a text field automatically populated with the answer that's selected.
For example, if the person checks the checkbox for "1", then the number 1 would appear in the text field at the end of the line. Same if the person selects the box for 2, 3, 4, or 5 - the text box would fill in with the correct number. Only one checkbox can be checked in the row. (I don't want to use radio buttons because there's no way to deselect them all once one has been selected.)
What script could I put in the text field (rather than in each individual checkbox)?
I have searched everywhere, but can't find the exact help I need. Can someone help? Thank you so much!
- Charlaine
Copy link to clipboard
Copied
This type of action has been answered many times but maybe not for 5 items specifically.
This requires a custom script and for that we need very specific information.
How do you want the situation when no check box has been selected handled?
This is a situation where one just concatenates the value of 5 field values.
One possible general solution could be:
function GetField(oDoc, cName)
{
var oField = oDoc.getField(cName);
if(oField == null) app.alert("Unable to access field " + cName + "!\nPlease check this field name.", 1, 0);
return oField;
} // end GetField function;
// clear result field;
event.value = "";
// array of field names to process;
var aNames = new Array("Check Box1", "Check Box2", "Check Box3", "Check Box4", "Check Box5");
// array to hold the found values;
var aValues = new Array();
// variable for field object to process;
var oCheck;
// loop through the field name to process;
for(var i = 0; i < aNames.length; i++)
{
// get specific field to process;
oCheck = GetField(this, aNames);
// only process non-null fields ane values not equal to "Off";
if(oCheck != null && oCheck.value != "Off")
{
// put field value into array;
aValues.push(oCheck.value);
} // end not null not Off
} // end field processing loop;
// populate result if we have data form check boxes;
if(aValues.length != 0)
{
// adjust last element if needed for " and ";
if(aValues.length > 1) aValues[aValues.length - 1] = " and " + aValues[aValues.length - 1];
event.value = aValues.join(", ");
}
Not this removes unfound fields and fields where no check box has been selected.
The above is a generalized solution since the code is not dependent upon a specific number of fields or field names. The number of fields and their names is controlled by the array "aNames" which holds the names of the field to be processed and the number of elements in this array controls the number of fields to process,
Find more inspiration, events, and resources on the new Adobe Community
Explore Now