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
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;
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?
Copy link to clipboard
Copied
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/