Skip to main content
Inspiring
September 30, 2020
Answered

Use Radio button to change textfield...

  • September 30, 2020
  • 2 replies
  • 4259 views

Hello I am new to adobe acrobat. I have a form with two radio button selection. If a customer selects, "Yes" radio button, a text field with "Yes" color background changes into Green, if selected  Radio button, "No", textfield,"No" color background color changes to "Red".

  • My radio button fields group name is, "MDC". My textfield name for "Yes" is, "MDC_Yes" & for no, "MDC_No". I appreciate first hand foe your help.

Thank You

Pet

 

 

This topic has been closed for replies.
Correct answer Adosh

I just noticed that you tried to employ Try67's code and then you went and tried my variation.

 

Before you continue with troubleshooting you have to decide which code to test with.

 

It if helps, my code is meant to be run directly from the radio buttons as a Mouse-Up action:  MDC_Yes radio button in my example has export value of "Choice1" and MDC_No radio button. has export value of "Choice2".

 

That said, are you getting the same error with both codes, even if the radio buttons are set as mutually exclusive with different export values each?

 

As I am running out of ideas., the only thing I can think of is to check the calutaion tab on both text fields "MDC_Yes" and "MDC_No" respectively. If you have any cuctom calculation scripts there you have to remove them to rule out if the problem is related to those custom calculation scripts, or post another screenshot to see what you have there.

 

I think the radio button part was already answered correctly.

 

You also need to provide us with  what you have running in TOTAL_EXHAUST_CFM" when you say it adds up the 10 fields and send the result to calculate the "TOTAL_EXHAUST".  

 

What code (if any) or calculation method are you using in the "TOTAL_EXHAUST_CFM" and the "TOTAL_EXHAUST" text fields??  


ls_rbls & Try67,

             Thank you for your help. Both codes works fine.  I found out that I made a text field name errors. I also delete the textfield with total exhaust cfm. The code works fine both of yours. I appreciate your follow ups and continuous help.

Thank you, Thank you, Thank you.

Pet

2 replies

ls_rbls
Community Expert
September 30, 2020

This also worked for me:

 

Create the pair of Radio Buttons with the same  name, but different export values fro each. For example, "Choice1" and "Choice2" respectively.

 

In the radio button with Choice1 export value using this script:

 

 

this.getField("MDC_Yes").value = "Yes"
this.getField("MDC_Yes").fillColor = color.green;
this.getField("MDC_Yes").readonly = true; 


this.getField("MDC_No").value = "";
this.getField("MDC_No").fillColor = color.transparent;
this.getField("MDC_No").readonly = true; 

 

 

 

And in the radio button with "Choice2" export value this script:

 

 

this.getField("MDC_No").value = "No"
this.getField("MDC_No").fillColor = color.red;
this.getField("MDC_No").readonly = true; 

this.getField("MDC_Yes").value = "";
this.getField("MDC_Yes").fillColor = color.transparent;
this.getField("MDC_Yes").readonly = true; 

 

AdoshAuthor
Inspiring
September 30, 2020

Thank you ls_rbls,

So when I applied the code under each javascript:

The "Yes" but didnt work.

The "No" but woks howeve when I select the "Yes" button the Red color remains.  I coudn't  figure out how. Any ideas. Thank you.

 

 

 

 

AdoshAuthor
Inspiring
October 7, 2020

In your last screenshot for step 3, see the fourth line of the code used ...look from top to bottom

 

See the line:

 

this.getField("MDC_No").value = " ";

 

The null value is expressed as "".

 

You have an extra blank space in between the quotes. Remove that blank space. Check the same line in the radio button code with export value of Choice2


ls_rbls,

      As you've mensioned, I removed the gap between "" on both MDC_Yes & NO. However, the code is not working. Question to you, does the location of the code matter? I put it under the Action tab - Mounse Enter Run a JavaScript.

Thank you.

try67
Community Expert
September 30, 2020

As the custom calculation script for "MDC_Yes" enter:

event.target.fillColor = this.getField("MDC").valueAsString=="Yes" ? color.green : color.transparent;

 

And for the "MDC_No" field enter:

event.target.fillColor = this.getField("MDC").valueAsString=="No" ? color.red : color.transparent;

AdoshAuthor
Inspiring
September 30, 2020

Thank you tey67,

I copy paste your code, however, the textfield's  backgroung color isn't changing. Am I missing anything?

Thank you

Pet

try67
Community Expert
September 30, 2020

Make sure to disable the Fields Highlighting option.