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

Radio Button color change JavaScript - To change based on selection

Explorer ,
Aug 28, 2020 Aug 28, 2020

Copy link to clipboard

Copied

I have a Radio Button Group with 2 choices(Group1) - a Yes and a No radio buttons. I would like for the color to change based on the which one is selected. When the No button is check, it should be Green and Yes should be white. When the Yes button is selected, it should be Red and the No should be white.

 

I have this currently entered  in the mouse up

event.target.fillColor = event.target.value=="Off" ? color.white : color.red;

But it changes both of the buttons. ot the color choice of the button that is chosen.

 

Any help would be appreciated. Thank you!

 

TOPICS
Acrobat SDK and JavaScript

Views

1.3K

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 Expert ,
Aug 28, 2020 Aug 28, 2020

Copy link to clipboard

Copied

I recently answered a similar question about check-boxes, but the same applies for radio-buttons.

See: https://community.adobe.com/t5/acrobat/different-fill-colors-for-same-name-check-boxes/m-p/11383110

Votes

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
Explorer ,
Aug 28, 2020 Aug 28, 2020

Copy link to clipboard

Copied

Thank you so much! I did actually search, but I couldn't find the "same" button thing.

Votes

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
Explorer ,
Aug 31, 2020 Aug 31, 2020

Copy link to clipboard

Copied

So I researched the post you recommended and have been trying to apply the code you have...

                    "To do it you would need to access the individual widget, which event.target doesn't do. So you would need to use something like this:

this.getField("CheckBox1.0").fillColor = (this.getField("CheckBox1").value=="Yes") ? color.green : color.transparent;

this.getField("CheckBox1.1").fillColor = (this.getField("CheckBox1").value=="No") ? color.yellow : color.transparent;   "

 

My problem is my naming conventions do not match above and I have not been able to figure it out.

My Radio Button is named "Group15" with 2 buttons named YES and NO I do not see where to add the .0 and .1 as indicated in the above script.

Votes

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 Expert ,
Aug 31, 2020 Aug 31, 2020

Copy link to clipboard

Copied

Simply use:

 

this.getField("Group15.0").fillColor = (this.getField("Group15").value=="YES") ? color.green : color.transparent;

this.getField("Group15.1").fillColor = (this.getField("Group15").value=="NO") ? color.yellow : color.transparent;

Votes

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
Explorer ,
Aug 31, 2020 Aug 31, 2020

Copy link to clipboard

Copied

LOL...Thank you!! I was trying to add the .0 to both fields.

 

Thank  you again for being so quick to answer!!

 

Votes

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
Explorer ,
Aug 31, 2020 Aug 31, 2020

Copy link to clipboard

Copied

Did you manage this to work? I could use same code but I can't get it to work.

I named my radio buttons "Group15.0  and Group15.1" I gave 15.0 value Yes and 15.1 value No.

I use code in both buttons as mouse up event but they don't change color and they don't act as radio buttons anymore. Do I use all code in both buttons or first part in 15.0 button and second part in 15.1 button?

Pls help I'm not sure what I'm doing wrong here.

Votes

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 Expert ,
Sep 01, 2020 Sep 01, 2020

Copy link to clipboard

Copied

Do not name them like that. Just use "Group15". The ".0" and ".1" parts are added automatically, behind the scenes.

Votes

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
Explorer ,
Sep 01, 2020 Sep 01, 2020

Copy link to clipboard

Copied

Thanks I fixed that now they act as radio buttons again, but can you help one more time pls, buttons don't change colors, they have export values of yes and no, I use codes as mouse up event. I probably still missing something just can't figure out what it is.

Votes

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 Expert ,
Sep 01, 2020 Sep 01, 2020

Copy link to clipboard

Copied

Is it "yes" and "no", or "YES" and "NO"? The two are not the same... For further help you will need to share your file with us.

Votes

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
Explorer ,
Sep 01, 2020 Sep 01, 2020

Copy link to clipboard

Copied

LATEST

Thanks, that was it, I had Yes instead of YES.

Votes

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