Skip to main content
Participant
May 31, 2021 7:56 PM UTC
Answered

Adobe Javascript Radio Buttons Coordinates

Hi there.  I'm trying to rename a radio button using JS by creating a new radiobutton field.  There are 3 options layed out:

[ ]  Option 1

[ ]  Option 2

[ ]  Option 3

 

I'm trying to get the coords for each option using f.rect; but it returns the same coords regardless of which option I have checked.  Is there a way to do this?

This topic is closed to new replies. Start a new post to keep the conversation going.
Thom Parker
Thom ParkerCorrect answer
Community Expert
May 31, 2021 8:09 PM UTC

When fields have the same name, they are essentially the same field. In a PDF, a field is really a virtual thing. It's a name with an associated value. What the user sees on the screen is called a Widget. So your radio button group is 1 field with 3 widgets. By default, this.getField("FieldName") returns the 1st widget. To get the coordinates of the other widgets the widget ID is appended to the FieldName. 

 

So this.getField("FieldName.0") gets the first widget and  this.getField("FieldName.1") gets the second widget, etc. 

 

 

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

9 replies

Thom Parker
Community Expert
Thom ParkerCommunity ExpertCorrect answer
Community Expert
May 31, 2021 8:09 PM UTC

When fields have the same name, they are essentially the same field. In a PDF, a field is really a virtual thing. It's a name with an associated value. What the user sees on the screen is called a Widget. So your radio button group is 1 field with 3 widgets. By default, this.getField("FieldName") returns the 1st widget. To get the coordinates of the other widgets the widget ID is appended to the FieldName. 

 

So this.getField("FieldName.0") gets the first widget and  this.getField("FieldName.1") gets the second widget, etc. 

 

 

Translate
Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Participant
May 31, 2021 8:29 PM UTC

That worked!  Would it have killed them to put that in the reference, LOL.

Translate
Bernd Alheit
Community Expert
Community Expert
Jun 1, 2021 8:06 AM UTC

The information about widgets is available in the Acrobat Javascript Reference.

Translate