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
  • 13613 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?

    try67
    Community Expert
    July 15, 2019

    Hi try67,

    I would like to change a no fill button to an orange button upon clicking the mouse.

    Since I'm planning to use specific colours, I tried this code:

    event.target.fillColor = (color.equal(color.["RGB",1,1,1], event.target.fillColor)) ? color.["RGB",1,0.6,0.3] : color.["RGB",1,1,1];

    I replaced the colours with the RGB codes (not sure if I'm doing it correctly...) but I got this message:

    SyntaxError: missing name after . operator 1: at line 2

    Not sure what I should do...

    Would really appreciate any help, thank you so much!


    Your RGB values have to adhere to what the script expects, which is a value between 0 and 1. If your values are in Hex then you need to convert them to decimals, and then divide by 255.. If they are already integers between 0 and 255 then you just need to divide them by 255.