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 16, 2023

Please explain what you're trying to achieve in simple text, not using (faulty) code examples.

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?