Set variable based on radio button response

Community Beginner ,
Apr 13, 2021 Apr 13, 2021

Copy link to clipboard

Copied

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.png

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

Views

253

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Apr 13, 2021 Apr 13, 2021

Copy link to clipboard

Copied

To check the value e.g.:

this.getField ("group Name").value

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Apr 13, 2021 Apr 13, 2021

Copy link to clipboard

Copied

app is a reserved keyword. Use a other name. 

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Apr 13, 2021 Apr 13, 2021

Copy link to clipboard

Copied

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;

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Apr 13, 2021 Apr 13, 2021

Copy link to clipboard

Copied

Where does you use the script? 

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Apr 13, 2021 Apr 13, 2021

Copy link to clipboard

Copied

LATEST

Try this:

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

Likes

Translate

Translate

Report

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