Highlighted

How do I make radio buttons populate text fields

New Here ,
Nov 05, 2020

Copy link to clipboard

Copied

I'm trying to use radio buttons to populate text fields depending on which choice is selected. 

I'm trying to create a java script to accomplish this, but am unfamiliar with scripting and am not getting a working result. Can someone assist with debugging the script below, or recommend an alternative. Thanks for your help.

Radio Button Group is "MemCategory"

Desired results in four text fields should be: 

Choice 1 text field "Individual" = $ 25, Choice 2 text field "Family" = $ 35, Choice 3 text field "Sponsor" = $ 50, Choice 4 text field "Patron" = $100

DRAFT SCRIPT

var v = this.getField("MemCategory").value; if (v=="Choice1") event.value = this.getField(Individual); "$ 25"; else if (v=="Choice2") event.value; this.getField(Family); "$ 35"; else if (v=="Choice3") event.value; this.getField(Sponsor); "$ 50"; else if (v=="Choice4") event.value; this.getField(Patron); "$100"; else event.value = "";

 

Thanks, again

Ed

 

TOPICS
PDF forms

Views

32

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

How do I make radio buttons populate text fields

New Here ,
Nov 05, 2020

Copy link to clipboard

Copied

I'm trying to use radio buttons to populate text fields depending on which choice is selected. 

I'm trying to create a java script to accomplish this, but am unfamiliar with scripting and am not getting a working result. Can someone assist with debugging the script below, or recommend an alternative. Thanks for your help.

Radio Button Group is "MemCategory"

Desired results in four text fields should be: 

Choice 1 text field "Individual" = $ 25, Choice 2 text field "Family" = $ 35, Choice 3 text field "Sponsor" = $ 50, Choice 4 text field "Patron" = $100

DRAFT SCRIPT

var v = this.getField("MemCategory").value; if (v=="Choice1") event.value = this.getField(Individual); "$ 25"; else if (v=="Choice2") event.value; this.getField(Family); "$ 35"; else if (v=="Choice3") event.value; this.getField(Sponsor); "$ 50"; else if (v=="Choice4") event.value; this.getField(Patron); "$100"; else event.value = "";

 

Thanks, again

Ed

 

TOPICS
PDF forms

Views

33

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
Nov 05, 2020 0
Engaged ,
Nov 05, 2020

Copy link to clipboard

Copied

Try use this as "Custom Calculation Script" of each field:

"Individual" field:
event.value = this.getField("MemCategory").valueAsString == "Choice1" ? "$ 25" : "";

"Family" field:
event.value = this.getField("MemCategory").valueAsString == "Choice2" ? "$ 35" : "";

"Sponsor" field:
event.value = this.getField("MemCategory").valueAsString == "Choice3" ? "$ 50" : "";

"Patron" field:
event.value = this.getField("MemCategory").valueAsString == "Choice4" ? "$ 100" : "";

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
Reply
Loading...
Nov 05, 2020 1
New Here ,
Nov 05, 2020

Copy link to clipboard

Copied

Thank you Nesa, your cutom calculation script did work.

But I think I have confused the question by saying that the "Individual," etc. fields were text. I think they should have been numeric. What would change in the script to make the result numeric?

 

After it populates with the answer, I am trying to total the selected radio button result with two other numeric fields. that are should be populated by check boxes. 

 

When my form tries to total the text fields, using the simple calculation "Value is the sum (+) of the following fields" "Individual" "Family," etc.  it selects the prior text field value, instead of the currently selected one. 

 

How do I make a checked box field populate a numeric field?

"AddPaper" should populate the numeric field "Paper." 

 

Then whatever the selected radio box field, i.e; "Individual" should combine with "Paper" to yield "Total"

 

Thanks again for your help 

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
Reply
Loading...
Nov 05, 2020 0
Engaged ,
Nov 05, 2020

Copy link to clipboard

Copied

To make them numeric you can format all fields to number and select currency sign then use these codes:
"Individual" field:
event.value = this.getField("MemCategory").value == "Choice1" ? 25 : "";

"Family" field:
event.value = this.getField("MemCategory").value == "Choice2" ? 35 : "";

"Sponsor" field:
event.value = this.getField("MemCategory").value == "Choice3" ? 50 : "";

"Patron" field:
event.value = this.getField("MemCategory").value == "Choice4" ? 100 : "";

"Paper" field:
event.value = this.getField("AddPaper").value != "Off" ? 100 : "";
Not sure do you get value from checkbox export value or you want to use like in code above?
Change 100 to your value.

In "Total" field:
var ind = Number(this.getField("Individual").value);
var fam = Number(this.getField("Family").value);
var spo = Number(this.getField("Sponsor").value);
var pat = Number(this.getField("Patron").value);
var pap = Number(this.getField("Paper").value);
event.value = ind+fam+spo+pat+pap;

Not 100% sure if thats what you wanted so test and let me know if it works for you.

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
Reply
Loading...
Nov 05, 2020 0
Ed Flax LATEST
New Here ,
Nov 05, 2020

Copy link to clipboard

Copied

Hi Nesa,

 
Hi Nesa,
 
Thank you so much for your help. These updates worked perfectly, after I learned where to place them through a bit of trial & error. I’m learning… with the help of you and the community.
Just great!
Ed
 

 

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
Reply
Loading...
Nov 05, 2020 0