Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Set variable based on radio button response

Community Beginner ,
Apr 13, 2021 Apr 13, 2021

I have four radio buttons on an Acrobat form and I would like to run some if statements based on the response to which radio button is clicked. I assume that you use Radio Button Choice in some way to determine the response, but I can't find any code that shows how to check the response.

russb64585541_0-1618331619749.pngexpand image

I've changed each of the radio buttons shown above to have different Radio Button Choice fields. Can someone provide an idea of what to do to set a variable in javascript based on which button they click?

 

Thanks,

Russ

 

TOPICS
Edit and convert PDFs , JavaScript , PDF forms
2.4K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 13, 2021 Apr 13, 2021

To check the value e.g.:

this.getField ("group Name").value

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 13, 2021 Apr 13, 2021

To get that variable, I currently have the following line:

 


//Check application type
var app = +getField("ApplicationType").value;

 

If I run the java console and set event.value = app, the output is [object app] when I am looking for the output to be Radio Button Choice.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 13, 2021 Apr 13, 2021

app is a reserved keyword. Use a other name. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 13, 2021 Apr 13, 2021

You weren't very clear what you need but if i got it right you want to use different variables depending which radio button is clicked. You can try soemthing like this:

var a = this.getField("Text1").value;
var b = this.getField("Text2").value;
var rb = this.getField("Group1");
if(rb.value == "Choice1")
event.value = a;
else if(rb.value == "Choice2")
event.value = b;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 13, 2021 Apr 13, 2021

I need to be able to have a radio button input that is used in if statements for another field value. I've changed all the Radio Button Choices to different text and I assume that if I set a variable like the following:

 

var appType = +getField("ApplicationType").value;

 

Then I set

 

event.value = appType;

 

that I will get the output to be the Radio Button Choice currently selected. I'm just not getting it to output that way. The way that radio button is set will have an impact on a field below, but I'm not sure how to use it in the Boolean logic.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 13, 2021 Apr 13, 2021

Where does you use the script? 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 13, 2021 Apr 13, 2021
LATEST

Try this:

var appType = this.getField("ApplicationType").value;
if(appType != "Off")
event.value = appType;
else event.value = "";

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines