Skip to main content
Known Participant
November 25, 2018
Question

how can I create a colour changing click button that will work in PDF reader? say original colour blue, click it, changes to green....

  • November 25, 2018
  • 1 reply
  • 13614 views

I am currently working on an interactive ebook......I want to add a click button to

the bottom of each page that will change colour from blue to green if it is clicked on..

I am using publisher to create the book and then saving it as PDF.

    This topic has been closed for replies.

    1 reply

    try67
    Community Expert
    November 26, 2018

    For future questions about scripts in PDF files you should really use this forum: JavaScript

    Regarding your question: Do you want it to change only once, or back and forth with each click?

    If only once then set the fill color as blue and then apply the following JavaScript code as the MouseUp event of the button:

    event.target.fillColor = color.green;

    If you want it to change back and forth, use this code:

    event.target.fillColor = (color.equal(color.blue, event.target.fillColor)) ? color.green : color.blue;

    May 17, 2019

    Hi there,

    This worked perfectly for a form I was creating - the feature to change it back and forth. But for some reason, when I try to set it to yellow it won't change back? Is there a reason why it won't work on yellow?

    Also, if I want to set it to a very specific color, is there a way to use color codes for this?

    May 17, 2019

    - It might have to do with the fact that color.yellow is a CMYK color and the rest are RGB... Although the equal method should convert them before comparing, according to the documentation. Maybe try it with a custom RGB yellow color.

    - Sure, that's possible. You can do it like this, for example:

    var newColor = (color.equal(color.red, event.target.fillColor)) ? color.blue : color.red;

    event.target.fillColor = newColor;

    this.getField("Name of other field").fillColor = newColor;


    Ok I will try the code - I did attempt to use codes previously but will play around with it some and see if I was missing something.

    The example you sent works great! The only difference is I need the "trigger" button to also carry the action. So they are actually mimicking each other.