Highlighted

Custom Calc with Radio Button (Troubleshooting)

Community Beginner ,
Aug 20, 2020

Copy link to clipboard

Copied

First time trying to use Custom Calculations in an Acrobat PDF, and I'm stymied.

 

What I'm trying to do

  • Show a numerical value (range of 0-3) in a text box 
  • That numerical value is dependent on a selection of a 7-option radio button  (radio button we'll call fRad)
  • The values assigned for the 7 options are all text, e.g. red, white, blue, black, gold, etc.

 

The code I'm using

var fM = this.getField("fRad").value;
if( fM != "black" ) event.value = 3;
else if( fM != "red" ) event.value = 2;
else if( fM != "white" ) event.value = 2;
else if( fM != "blue" ) event.value = 2;
else if( fM != "gold" ) event.value = 1;
else {event.value= 0};

 

The problem

Regardless of which option is selected in the radio button, the APts value always returns as 3 (the value that would correspond with first option being selected in radio button)

 

So where am I going wrong?

 

Bonus Rookie Savior Question

If I also wanted to add a dynamic numerical value to the number associated with the radio button option selected, how would I need to further tweak my code?

TOPICS
General troubleshooting, How to, PDF forms

Views

71

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

Custom Calc with Radio Button (Troubleshooting)

Community Beginner ,
Aug 20, 2020

Copy link to clipboard

Copied

First time trying to use Custom Calculations in an Acrobat PDF, and I'm stymied.

 

What I'm trying to do

  • Show a numerical value (range of 0-3) in a text box 
  • That numerical value is dependent on a selection of a 7-option radio button  (radio button we'll call fRad)
  • The values assigned for the 7 options are all text, e.g. red, white, blue, black, gold, etc.

 

The code I'm using

var fM = this.getField("fRad").value;
if( fM != "black" ) event.value = 3;
else if( fM != "red" ) event.value = 2;
else if( fM != "white" ) event.value = 2;
else if( fM != "blue" ) event.value = 2;
else if( fM != "gold" ) event.value = 1;
else {event.value= 0};

 

The problem

Regardless of which option is selected in the radio button, the APts value always returns as 3 (the value that would correspond with first option being selected in radio button)

 

So where am I going wrong?

 

Bonus Rookie Savior Question

If I also wanted to add a dynamic numerical value to the number associated with the radio button option selected, how would I need to further tweak my code?

TOPICS
General troubleshooting, How to, PDF forms

Views

72

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
Aug 20, 2020 0
Adobe Community Professional ,
Aug 20, 2020

Copy link to clipboard

Copied

You need to rename all the radio buttons with the same fieldname and then assign the colors red, white, blue, black, gold, etc. as the export value for each independent radio button.

 

If the radio buttons are not used in a mutually exclusive fashion this script won't work correctly.

 

 

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...
Aug 20, 2020 0
Community Beginner ,
Aug 20, 2020

Copy link to clipboard

Copied

Thanks for yoru response.  I think I'd done this.

 

  1. For each of those 7 radio options, I'd clicked on Properties and on the General tab given them the same exact Name value.  
  2. And then on Options tab, I gave each the text value in Radio Button Choice field. (I think that's what's meant by assigning export value)

 

I am a total rookie, so if this is not what you're suggesting, please set me straight.

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...
Aug 20, 2020 0
Adobe Community Professional ,
Aug 20, 2020

Copy link to clipboard

Copied

yes that is correct!

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...
Aug 20, 2020 1
Community Beginner ,
Aug 20, 2020

Copy link to clipboard

Copied

Terrific help.  I'm very grateful.  So, I'll ask about my Bonus Rookie Question.  How would I add another variable into this calculation? 

 

Using all of the above, what if I needed to factor in another varible (value range 0-4)?   How do I best make this additional calc accumulate a value, so that whatever is calculated in the first formula is increased by this?

 

I apologize for such a simple question, but really appreciate the help.  And yes, this is my first time working in JS and Acrobat with calcs. 🙂

 

var X = this.getField (Rank).value;

if( X  >= 100 ) event.value = 4; {add 4 to calc above
else if (X >=75 ) event.value = 3; {add 3 to calc above

else if (X >=50 ) event.value = 2; {add 2 to calc above

else if (X >=25 ) event.value = 1; {add 1 to calc above

else {event.value= 0};   {add 0 to calc above

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...
Aug 20, 2020 0
ls_rbls LATEST
Adobe Community Professional ,
Aug 20, 2020

Copy link to clipboard

Copied

Try something like this:

 

var X = this.getField ("Rank").value;
var Y = this.getField ("APts").value;


if (Y !=="") {

if( X  >= 100 ) event.value = Y+4;

else if (X >=75 ) event.value = Y+3;

else if (X >=50 ) event.value = Y+2;

else if (X >=25 ) event.value = Y+1;
}
else event.value=Y+0;; 

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...
Aug 20, 2020 0
Engaged ,
Aug 20, 2020

Copy link to clipboard

Copied

Replace != with ==

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...
Aug 20, 2020 1
Community Beginner ,
Aug 20, 2020

Copy link to clipboard

Copied

Thank you, NesaNurani.  This did the trick.  This is exactly what was wrong.  

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...
Aug 20, 2020 0
Adobe Community Professional ,
Aug 20, 2020

Copy link to clipboard

Copied

Also it is easier if you run this script as a custom calcutaion script of Field("fRad") .

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...
Aug 20, 2020 1
Adobe Community Professional ,
Aug 20, 2020

Copy link to clipboard

Copied

+++ CORRECTION

 

I meant to say that your current script is plcaed i in the wrong field if you want to use it like that.

 

When you use radio buttons under a single parent name with a different export value is referred to a mutually exclusive relationship. Meaning that you'll be able to select a radio button at a time and the checked/unchecked state will change as you tick another radio button.

 

There's also no dynamic numeric values, just export values. You can assign export values via the Options property ta of that field, or, via javascript. 

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...
Aug 20, 2020 1