Skip to main content
Participant
Mar 5, 2022 3:37 AM UTC
Question

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

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 is closed to new replies. Start a new post to keep the conversation going.

3 replies

Nesa Nurani
Community Expert
Community Expert
Mar 5, 2022 5:52 AM UTC

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?

 

Translate
MycomacAuthor
Participant
Mar 5, 2022 5:55 PM UTC

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"

 

 

 

Translate
Thom Parker
Community Expert
Community Expert
Mar 7, 2022 8:04 PM UTC

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.

 

 

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