Skip to main content
Inspiring
August 24, 2023
Question

Toggle check box = words in text box

  • August 24, 2023
  • 3 replies
  • 589 views

Hi all,

 

Creating a new string because I still need help.  I need words to be produced in a text box when check boxes are toggled.  Some I need followed by a comma, some just by a space.  Below is an example of my form, followed by my current code.

 

 

If every one of the above are checked it should produce "Rec'd PDF, DD, BC".  Obviously, this code is not working, but I don't know how to fix it.

 

var fields = ["CB1"];
var texts = ["Rec’d"];
var selectedTexts = [];
for (var i=0; i<fields.length; i++) {
if (this.getField(fields[i].valueAsString!="Off")) selectedTexts.push(texts[i]);
}
event.value = selectedTexts.join(" ");

var fields = ["CB2", "CB3", "CB4"];
var texts = ["PDF", "DD", "BC"];
var selectedTexts = [];
for (var i=0; i<fields.length; i++ {
if (this.getField(fields[i].valueAsString!="Off")) selectedTexts.push(texts [i]);
{
event.value = selectedTexts.join(", ");

This topic has been closed for replies.

3 replies

Thom Parker
Community Expert
Community Expert
August 25, 2023

The script doesn't look bad. But there are a couple of obvious issues. 

#1  The last "if" is missing both the closing ")" and the closing "}"

#2  The second "event.value =" is overriding the first one.  It would be better to create a string variable to accumulate the string values. Then set "event.value" at the end.

 

Another suggestion. Set the checkbox export values to the output string value. Then the script can just concatonate the export values.  

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Bernd Alheit
Community Expert
Community Expert
August 24, 2023

Check the Javascript console for errors. 

Bernd Alheit
Community Expert
Community Expert
August 24, 2023

What is not working?

Info: The second part of your script overrides the result of the first part. 

Inspiring
August 24, 2023

Well currently the entire thing is not working.  Which is why I am asking for help.