Skip to main content
New Participant
April 30, 2020
Question

Button actions using JavaScript

  • April 30, 2020
  • 2 replies
  • 547 views

Hi,

I'm creating an interactive Bingo board so my student can complete activities at home. The parent will click the button to mark done.

 

I found the following code to change the color of a button.

 

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;

 

Is there a way to add to the change back and forth code to add words. I want add the word 'Done'? Blue would be blank. Once the button is clicked, it would change to green and the word done would appear. I actually would prefer yellow but I will just change the word.

 

Also, is there a way to add the same property to all buttons at once or do I need to add the script to each bingo board?

I really would like a transparent circle to cover the square but that is a little too advanced for me right now!

 

Thank you for your help!!!

This topic has been closed for replies.

2 replies

Thom Parker
Adobe Expert
April 30, 2020

The best way to develop something like this is to put the button code into a folder level function and then call the function from each button. For example

function ToggleColor()
{
    event.target.fillColor = (color.equal(color.blue, event.target.fillColor)) ? color.green : color.blue;
}

 

If there are a lot of buttons, then you can use a console script to set them all up. If the fields are named correctly you can do it with a single line of code. 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
whatawhatAuthor
New Participant
April 30, 2020

I just learned how to add 'done' as a label and change the color to black. When the button is clicked and the color of the button turns yellow, the word 'done' appears.