Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
2

Toggle check box = words in text box

Explorer ,
Aug 24, 2023 Aug 24, 2023

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.

 

Screenshot 2023-08-22 073320.jpg

 

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(", ");

TOPICS
How to , JavaScript , PDF forms
427
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 24, 2023 Aug 24, 2023

What is not working?

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 24, 2023 Aug 24, 2023

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 24, 2023 Aug 24, 2023

Check the Javascript console for errors. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 25, 2023 Aug 25, 2023
LATEST

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 PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines