Skip to main content
Participant
March 5, 2022
Question

Javascript to select correct radiobuttons based on a field value in a table

  • March 5, 2022
  • 1 reply
  • 901 views

I have a table of records that contains a field named "LeafType".  The values in the LeafType field are either "Leaf (young)" or "Leaf (old)".

 

I have an Acrobat Form with a 2 button radiobutton Group named "LeafType".  One button is named "Young", and the other button is named "Old".

 

How would I write a javascript to set (select) the appropriate button if  getField('LeafType').value  == "Leaf (young)" , or when getField('LeafType').value  == "Leaf (old)"?

This topic has been closed for replies.

1 reply

Nesa Nurani
Community Expert
Community Expert
March 5, 2022

Is first field in same form as radio buttons, because  you can't have radio buttons and that field with same name?

Is the first field a dropdown with only those 2 values?

 

MycomacAuthor
Participant
March 5, 2022

I am using an Acrobat plug-in called Evermap to merge data from an Excel Worksheet (attached) to an Acrobat Form (attached). The field "LeafType" contains 1 of 2 values ("Leaf (young)" or "Leaf (old)").

 

I want to populate this Adobe Form (image below) using the data from the records in the Excel Worksheet.  I can populate all of the other fields on the Form successfully from the worksheet data, but I dont know how to "activate" the proper buttons (or checkboxes if more appropriate) based on the records "LeafType".   The following image shows the desired output.  I need a javascript that will look at the value in LeafType, and if LeafType = "Leaf (young)", the return "Yes", else "No"

 

 

 

Thom Parker
Community Expert
Community Expert
March 7, 2022

So you want to transform data loaded from the spreadsheet into values that match radio button selections on your form.  To do this you would need a text field to recieve the merged data first, then a script that would run after the merge to convert and copy the data to the radio button fields. This is an awkward strategy.

 

A better solution is to change the name of the leaf radio buttons to have the same name (i.e. the name of the column in the spreadsheet), and set the export values of each to match the possible data values in the spreadsheet.

 

 

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