Skip to main content
Scott547
Participant
December 26, 2022
Question

Set the value of a radio button if a text field contains data.

  • December 26, 2022
  • 3 replies
  • 1766 views

I am attempting to set the value of a radio button is a text box contains data. I get the error messahe "SyntaxError: invalid property id 1: at line 2.

 

Here is my code.

 

If({{#assign "involvedPersonsVar"}} {{listIndex externalOffenses "involvedPersons" 1 }} {{/assign}} {{listIndex "involvedPersonsVar" "lastName" 1 filterField="involvement.name" filterValue="VICTIM_IN_OFFENSE"}}().length > 0)

this.getField(“Wit1").value="Victim";

else

this.getField("Wit1").value="";

 

Any help would be appreciated.

This topic has been closed for replies.

3 replies

Nesa Nurani
Community Expert
Community Expert
December 27, 2022

Use this as 'Validation' script of text field:

this.getField("Wit1").value = event.value == "" ? "Off" : "Victim";

Scott547
Scott547Author
Participant
January 16, 2023

Thank you for the input Nesa but the code does not work.

I'm still searching how to set one of 3 radio buttons in the same group based upon data in a test field.

try67
Community Expert
Community Expert
December 26, 2022

This is not valid Acrobat JS syntax. Far from it...

Scott547
Scott547Author
Participant
December 27, 2022
My current script follows. I would appreciate your input to make it correct
syntax.

this.getField("Wit1").value="Off";

// Cleared radio buttons

If({{#assign "involvedPersonsVar"}} {{listIndex externalOffenses
"involvedPersons" 1 }} {{/assign}} {{listIndex "involvedPersonsVar"
"lastName" 1 filterField="involvement.name"
filterValue="VICTIM_IN_OFFENSE"}}().length>0){this.getField("Wit1").value="Victim";}else{this.getField("Wit1").value="Off";}
try67
Community Expert
Community Expert
January 17, 2023
I have a fillable PDF form that gets data from a database. Fields on the
form are for a passenger, witness or victim. There is a radio button that
identifies which type of individual is listed. The field is to populate if
there is a victim in the data. If so the name will be tagged from the
database. If not, the field will be blank. I would like to have the radio
button with Victim checked if there is data.

Please let me know if this is unclear or you need anything.

How is the data being imported into the file, exactly? The issue is that importing data doesn't usually trigger any calculation scripts, so you'll have to do so manually, or place the code as a doc-level script, and then re-open the file after importing the data for it to "kick in".

Legend
December 26, 2022

Hello @Scott547,

 

Take a look here https://acrobatusers.com/forum/javascript/set-radio-button-based-value-another-field/ to see if it helps you.

 

Regards,

Mike

Scott547
Scott547Author
Participant
December 26, 2022

Mike,

 

Thank you for your quick response. I checked out the link and I get the same error code as before. I have a Radio button (Wit1) with 3 options, :Witness", "Passenger" and "Victim". I have tagged the name filed from another program to fill in the PDF so I know that if data is present it will be a victim name and the length will be greater than 0. Then I only want to check the "Victim" radion button. If there is no name, then I do not want to have any button checked. I did add the code to turn off the button at the beginning. Any ideas?