Skip to main content
Participant
May 31, 2021
Answered

Adobe Javascript Radio Buttons Coordinates

  • May 31, 2021
  • 1 reply
  • 2641 views

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 has been closed for replies.
Correct answer Thom Parker

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. 

 

 

1 reply

Thom Parker
Community Expert
Thom ParkerCommunity ExpertCorrect answer
Community Expert
May 31, 2021

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
Participant
May 31, 2021

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

Bernd Alheit
Community Expert
Community Expert
June 1, 2021

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