Skip to main content
Kris Hunt
Legend
March 13, 2019
Answered

Set the value of a radio button with Javascript

  • March 13, 2019
  • 1 reply
  • 4401 views

Quick syntax question: If I have a radio button group called "Answer" with the options "Yes", "No", and "Maybe", how can I use Javascript to select one of those options?

This topic has been closed for replies.
Correct answer try67

this.getField("Answer").value = "Maybe";

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
March 13, 2019

this.getField("Answer").value = "Maybe";

Kris Hunt
Kris HuntAuthor
Legend
March 13, 2019

Thank you.

Kris Hunt
Kris HuntAuthor
Legend
March 13, 2019

On my test form, I have a dropdown menu (named "Selection") where the user makes their selection, and then on another page, that same selection is displayed in a radio button group (named "Result") with that option checked. The export values in the dropdown and the radio button group are the same. Here's what I did:

On the dropdown menu field, I added a Javascript to be executed on MouseUp:

var mySelection = this.getField("Selection").value;

this.getField("Result").value = mySelection;

I also checked the "Commit selected value immediately" option.

It's not working properly; the selections in the radio group are always one selection behind the selections in the dropdown list, exactly as they would be if I had not selected the "Commit selected value immediately" option. What am I doing wrong?