Skip to main content
Known Participant
February 23, 2023
Answered

Radio Buttons, Check Boxes and import Data

  • February 23, 2023
  • 1 reply
  • 5895 views

Hi,  I have a form that is autofilled by importing data from a text file.

 

Problem #1:

I have a radio button with 3 options as well as an "Other" option with a textfield.  The value of the radio buttons are "A", "B", "C", "Other". If the data imported has a value that is not  "A, B, or C", I want the "Other" radio button to be selected and the value to be autofilled into the textfield.  How do I go about scripting this scenerio? I'm not well versed in JavaScript.  I have a hidden textfield that I'm thinking it could hold the script, but I don't know where to begin. 

 

Problem #2:

The form has check boxes for the months of the year....Jan, Feb, March, etc.  There can be multiple months selected.  The column in the text file is called "Skip Month" and an example of the value from the "Skip Month" column is "Jan/Feb".  The check box field names are "Jan", "Feb", "March", etc. and the export values are "On".

 

How do I use the data from the text file ("Skip Month" and "Jan/Feb") to make it so the appropriate check boxes are selected? In this case, "Jan" and "Feb" - as shown below.

This topic has been closed for replies.
Correct answer Thom Parker

Hi, Thank you for your patience and I appologize for my ignorance.  

 

You are correct, there were mulitple actions, so this time I cleared the console and then did an import. The console indicates:

Calculate Source: [object Field]

Still not working. I've attached the test document and the text file used for import.  Would you mind looking at this for me and tell me what is going on.


Here's the correction. On reset "event.source" is null. On import, "event.source" is the same as "event.target".  

 

// Detect reset or import event
if(event.source == event.target)
{
   var oRadios = this.getField("RadioButton");
   var oOther = this.getField("Other");
   oOther.value = "";
   if(event.value == "")
      oRadios.value = "Off";
   else{
     // First determine if the value is one of the radio exports
		if(oRadios.exportValues.some(function(a){return a == event.value;}))
		{// data value is one of the exports. 
			oRadios.value = event.value;
		}
		else
		{// Data value is an other value
			 oRadios.value = "Other";
			 oOther.value = event.value;
		}
   }
}

 

1 reply

Thom Parker
Community Expert
Community Expert
February 23, 2023

You can start by exporting data to a text file and see what it looks like in the text file. All these things are handled automatically 

 

 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
meem23Author
Known Participant
February 24, 2023

Importing the data isn't going to solve this problem.  It's how to handle the data once it's imported.  If the values do not match what the form values are, then there will be nothing populated.  For my problem #1, there is an Other option.  If the data has something other than A, B, or C, I want this value to poputate into the Other (specify) text field as well as selecting the Other button.

Thom Parker
Community Expert
Community Expert
February 24, 2023

Well then, we'll need some more infomation.

How exactly is this text data formatted? Where does it come from? How are you planning on importing it into the PDF(i.e., what JS function)?

Can the text data be modified before importing into the PDF?

 

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