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

Button to change color when it's clicked and when clicked again going back to the original color.

New Here ,
May 06, 2024 May 06, 2024

Copy link to clipboard

Copied

Hi I've been really struggling with making a button to change color.

 

Basically, I have a yellow button called 'button1', and when I click this button, the button will be blue,

and when I click again, it goes back to yellow again.

 

I found this code from other post, but it only works, just one-time color change, not going back to the original color after clicking again. Thank you.

 

this.resetForm();
for (var i = 0; i < this.numFields; i++) {
var oFld = this.getField(this.getNthFieldName(i));
oFld.fillColor = color.transparent;
}

event.target.fillColor = ["RGB", 255/255, 255/255, 204/255]; // light yellow

 

TOPICS
JavaScript , Modern Acrobat , PDF , PDF forms

Views

504

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 ,
May 06, 2024 May 06, 2024

Copy link to clipboard

Copied

This code does not do what you have described, not even close. 

You said you have a button that changes color when clicked.

Do you mean you want a button that changes color when clicked? 

 

Here is Mouse Up code for toggling the color of a button.

 

event.target.fillcolor = color.equal(color.blue,event.target.fillcolor)?color.yellow:color.blue;

 

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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
New Here ,
May 06, 2024 May 06, 2024

Copy link to clipboard

Copied

Thank you! I actually tried the code as well, but when I inserted specific RGB color codes instead of using just the yellow and blue, it didn't work at all. Do you know how to do this?

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 ,
May 06, 2024 May 06, 2024

Copy link to clipboard

Copied

LATEST

Did you look at the console window to see if any errors were reported? 

Why use the color codes? And what do you mean by color codes?

Acrobat has a very specific way of specifying colors. See this article:

https://acrobatusers.com/tutorials/using-colors-acrobat-javascript/

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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