Skip to main content
Participating Frequently
August 16, 2023
Answered

Filling multiple copies of checkbox based on field value

  • August 16, 2023
  • 3 replies
  • 1345 views

I have a mostly Y/N test that will fill in an answer sheet for scanning using checkboxes formatted as circles on the answer sheet.

There a couple of questions that require Y/N answers, then a value input into a text box. I use same form field names with diferent export values to auto fill the answer sheet.

 

Need a way to auto fill based on value of the text box:

Question 36 Y/N then QI36 text box enter value (0-9)

on answer sheet I have SFA36#0-SFA36#9 for the circled checkboxes export values of these are 0-9, respectively; to allow only one check box to be checked. 

 

I would like the value entered in  QI36 to auto fill the correct checkbox (fill the circle) 

tried a couple data validations that i found in this forum, but none are cheching any boxes.

 

Please help.

This topic has been closed for replies.
Correct answer Thom Parker

In your example the field "SFA36", although it has 9 instances, is a single field. The value of that field is determined by the export values of the individual instances. 

You can read more about how checkboxes work here:

https://www.pdfscripting.com/public/Checkboxes-and-Radio-Buttons.cfm

 

If you set the export values to 0-9, then a direct assignment from the text box will check the correct checkbox. 

Put this code in the Validation script for the "QI36" text box.

 

if((event.value != "") && Number.isInteger(event.value) && (event.value >= 0) && (event.value <= 9))
    this.getField("SFA36").value = event.value;
else
    this.getField("SFA36").value = "Off";
 

 

 

 

3 replies

Thom Parker
Community Expert
Thom ParkerCommunity ExpertCorrect answer
Community Expert
August 16, 2023

In your example the field "SFA36", although it has 9 instances, is a single field. The value of that field is determined by the export values of the individual instances. 

You can read more about how checkboxes work here:

https://www.pdfscripting.com/public/Checkboxes-and-Radio-Buttons.cfm

 

If you set the export values to 0-9, then a direct assignment from the text box will check the correct checkbox. 

Put this code in the Validation script for the "QI36" text box.

 

if((event.value != "") && Number.isInteger(event.value) && (event.value >= 0) && (event.value <= 9))
    this.getField("SFA36").value = event.value;
else
    this.getField("SFA36").value = "Off";
 

 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Participating Frequently
August 16, 2023

Thanks, Thom.

The key component works like a charm !

somehow when i put the the first part for error corections in it, and the last part else off statement nothing happens.

 

(I have seen your name all over this forum, and believe me, we appreciate your time and effort!)

Nesa Nurani
Community Expert
Community Expert
August 16, 2023

Use this as 'Validate' script of text field:

this.getField("SFA36").value = event.value;

Participating Frequently
August 16, 2023

Nesa - you had the gist of getting this done, Many thanks

Participating Frequently
August 16, 2023

UPDATE: I can get this to work if I have Unique Field Names:
QI36 text box value (0-9)
Answer Sheet Field Names QA360-QA369, then usevalidation on QI36:

this.getField("QA360").checkThisBox(0, event.value=="0");

-repeating line for each unique value of checkbox QA361-QA369

 

Participating Frequently
August 16, 2023

BUT I really like the idea of not having to use unique values - too confusing. The copy paste function of checkboxes  creates unique values already with the '#0' and all my forms seam logical. Is there a trick to referencing the fields I do not know about?

Thom Parker
Community Expert
Community Expert
August 16, 2023

The "#0" is not a real part of the field name. It indicates the instance (also called widget) number of the field.

If you don't need a group of checkboxes to be mutually exclusive (i.e. these fields are read only and will not be entered by the user) then give them unique names. Such as "SFA36-0", "SFA36-1", etc.  How the form is organized and scripted is up to you. But it is a good idea to understand how things work before you go down a specific path. Read the article. How fields are named directly affects the efficiency, difficulty, and maintainability of the scripting. 

 

 

 

 

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