Skip to main content
DemonFangs
Participant
March 9, 2018
Answered

Identifying two separate fields with the same name

  • March 9, 2018
  • 3 replies
  • 721 views

I have a pair of check-boxes with the same field name to simulate a radio button. I would like to select both fields separately in a javascript. I can see on the field tab that they are denoted by "Same_Name#1" and "Same_Name#2", I tried calling them such but with no luck.

Will appreciate any help.

Using Acrobat DC Pro

This topic has been closed for replies.
Correct answer try67

You can access the whole group using just its base-name, like this:

this.getField("Same_Name")

Or you could access individual widgets using a period followed by an index number, like this:

this.getField("Same_Name.0")

this.getField("Same_Name.1")

etc.

3 replies

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
March 11, 2018

You can access the whole group using just its base-name, like this:

this.getField("Same_Name")

Or you could access individual widgets using a period followed by an index number, like this:

this.getField("Same_Name.0")

this.getField("Same_Name.1")

etc.

Community Expert
March 12, 2018

Hi try67 ,

I'm not so much into JavaScript for Acrobat.


What I wonder: Would method getField() accept a function where one could filter with e.g. a regular expression?

There is no plural in the name of the method, but it would return an array of fields with your first example? Amazing.


FWIW: I'm more into ExtendScript where we have the method Folder.getFiles() that is accepting a "mask" as argument that could be a function where one could filter files by name with e.g. a regular expression returning an array of filtered files.

Thanks,
Uwe

try67
Community Expert
Community Expert
March 12, 2018

No, getField only returns a single Field object.

However, if you use it to access the whole group then you could then use the Field object's getArray() function to access all of the widgets under that group. For example:

var fields = this.getField("Same_Name").getArray();

The "fields" variable will be an array of Field objects.

JR Boulay
Community Expert
Community Expert
March 11, 2018

Any checkbox must have an unique "Export value" (Properties : Options) to act as radio-buttons.

To select a checkbox you just have to set its value:

this.getField("checkbox").value = "Yes";

To deselect the checkboxes group:

this.getField("checkbox").value = "Off";

Acrobate du PDF, InDesigner et Photoshopographe
Community Expert
March 10, 2018

Are you looking for a JavaScript solution with Acrobat DC Pro?
Then you posted in the wrong forum. This one here is about InDesign Scripting.

For JavaScript with PDF see into this here:

JavaScript

Should a moderator move this thread to the linked forum?

Regards,
Uwe

DemonFangs
Participant
March 10, 2018

Is there a way I can move this myself? Or delete the post?