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

Javascript checked boxes filling a text box

New Here ,
Mar 03, 2020 Mar 03, 2020

Copy link to clipboard

Copied

So here's a Javascript I'm using to check read only checkboxes:

 

var v = event.target.value;
var f = this.getField("Comp 1");
f.value = v;
var v = event.target.value;
var f = this.getField("Comp 6");
f.value = v;
var v = event.target.value;
var f = this.getField("Comp 11");
f.value = v;
var v = event.target.value;
var f = this.getField("Comp 16");
f.value = v;

 

As stated, comp 1, 6, 11, and 16 are read only boxes. The checkbox that contains the above script is named "Selection 1". As shown in the script above, when "Selection 1" is checked, it checks 1, 6, 11, and 16. What I need to happen is that when those read only boxes are checked, it fills out a text field called "List", but in a list format as follows:

Spades (this is Comp 1)

Clubs (This is Comp 6)

Diamonds (This is comp 11)

Hearts (This is Comp 16)

 

Instead of:

Spades, Clubs, Diamonds, Hearts.

 

I've tried to put the following script in Comp 1:

 

if (this.getField("Comp 1").value!="Off")
this.getField("List").value = "Spades";
else this.getField("List").value ="";

 

But nothing shows up in the "List" text field. I've tried undoing the read only thing and just checking the boxes, and that kind of works, but the problem is that each new check mark overwrites the last checkbox entry (Comp 6 overwrites Comp 1, etc). I need it to not do that. I need it to list each checked box without deleting the prior entry. In a nutshell:

Selection 1--> Checks Comp 1, 6, 11, and 16 --> Comp 1, 6, 11, 16 checked--> Fills out List.

 

Just to be clear, I know next to nothing about Javascript. I picked up the above scripts in the past few days from the community posts here and edited them to work for what I have going on. Any and all help would be appreciated! Thank you!

TOPICS
Acrobat SDK and JavaScript

Views

87

Likes

Translate

Translate

Report

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 ,
Mar 03, 2020 Mar 03, 2020

Copy link to clipboard

Copied

Use a calculation script in the text box to build the list of items based on the values of the checkboxes.

Watch the videos here to get a handle scripting Acrobat.

https://www.pdfscripting.com/public/Free_Videos.cfm#FormJS

Here are articles on calculations:

https://acrobatusers.com/tutorials/how-to-do-not-so-simple-form-calculations/

https://www.acrobatusers.com/tutorials/conditional-execution/

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Likes

Translate

Translate

Report

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
New Here ,
Mar 03, 2020 Mar 03, 2020

Copy link to clipboard

Copied

A lot of the links don't pull up a video, or they don't have a link at all. Not even the Calculation script thing.

Likes

Translate

Translate

Report

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 ,
Mar 03, 2020 Mar 03, 2020

Copy link to clipboard

Copied

LATEST

The top 3 videos under form scripting are free and have link. The others are for members only. But you only need the first 3 to get started.

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Likes

Translate

Translate

Report

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