Skip to main content
Participating Frequently
November 9, 2023
Answered

Button Color Change on Hover and Exit

  • November 9, 2023
  • 2 replies
  • 1280 views

Hi,

I searched this forum but couldn't find an answer to my inquiry. I have a Adobe form with a button that I want to change color when the user hovers over it (MouseEnter) and changes color back when the user no longer hovers over it (MouseExit). The button default RGB color is set as 0,0,255. The following Javascript doesn't seem to work. Am I doing something wrong? Thank you!

 

Mouse enter

event.target.fillColor = (color.equal(["RGB", 0/255,0/255,255/255], event.target.fillColor)) ? ["RGB", 240/255,255/255,255/255] : ["RGB", 0/255,0/255,255/255];

 

Mouse exit

event.target.fillColor = (color.equal(["RGB", 240/255,255/255,255/255], event.target.fillColor)) ? ["RGB", 0/255,0/255,255/255] : ["RGB", 240/255,255/255,255/255];

This topic has been closed for replies.
Correct answer Thom Parker

This type of comparison won't work. But there's is no reason to do it anyway.

Use this: 

 

Mouse enter

event.target.fillColor = ["RGB", 240/255,1,1];

 

Mouse exit

event.target.fillColor =  ["RGB", 0,0,1] ;

 

 

2 replies

Thom Parker
Thom ParkerCorrect answer
Community Expert
November 10, 2023

This type of comparison won't work. But there's is no reason to do it anyway.

Use this: 

 

Mouse enter

event.target.fillColor = ["RGB", 240/255,1,1];

 

Mouse exit

event.target.fillColor =  ["RGB", 0,0,1] ;

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Participating Frequently
November 13, 2023

Great, this worked! Thank you.

try67
Community Expert
November 9, 2023

Using custom colors with fractional values is very tricky as they can be adjusted behind the scenes to something else, and then the comparison will fail. I suggest using something else, like the field's tooltip.