Create a Toggle Button With Text, Color, and Date in Adobe Acrobat
Question details
Create a PDF form button that switches its color and text and records when it was pressed.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- A PDF form needs a button that alternates between transparent and colored states while updating a separate date and time field.
- Observed behavior
- The existing button script toggles the fill color, but the user also wants to change the displayed text and record the current time in another field.
Open the PDF in Adobe Acrobat and make sure you can edit its form fields. Identify the exact name of the text field that will store the date and time.
Add a JavaScript toggle to the Acrobat form button
Use a button action to switch its fill color and caption and timestamp each press in a separate text field.
This example uses green for the on state and a transparent fill for the off state. It updates the timestamp on every press, including when the button is switched off.
In Acrobat, open All tools > Prepare a form. Add or select a button, then add a text field named datefield for the timestamp.
Open the button's Properties. On the Options tab, choose a label-only layout and set an initial caption such as Off. On the Appearance tab, set the fill color to transparent and choose a readable text color.
In button Properties, open the Actions tab. Set Select Trigger to Mouse Up, choose Run a JavaScript, and click Add. Enter this script: var isOn = color.equal(event.target.fillColor, color.transparent); event.target.fillColor = isOn ? color.green : color.transparent; event.target.buttonSetCaption(isOn ? "On" : "Off"); var dateField = this.getField("datefield"); if (dateField) { dateField.value = util.printd("mm/dd/yyyy HH:MM:ss", new Date()); }
Click OK to save the action, close form editing, and click the button twice. Check that the color and caption alternate and that datefield shows the time of each press.

View and work with PDFs alongside Office files in WPS Office
WPS Office is a free, lightweight alternative with a familiar interface for working with PDFs and Office documents. It can help you move between common file formats, but it does not replace Acrobat's JavaScript form-button setup.

Frequently Asked Questions
How do I change the button's text when its color changes?
In the button's Mouse Up JavaScript action, use event.target.buttonSetCaption() to set the caption. The example sets it to On for green and Off for transparent.
Why isn't the date field updating?
In Prepare a form, open the text field's Properties and check its exact name. Use that name in this.getField("datefield") in the button script, then test the button again.
Can I use a different color for the on state?
Yes. In the button's JavaScript action, replace color.green with another Acrobat color, such as color.red. The script still uses color.transparent for the off state.
Will the toggle work in every PDF viewer?
Not necessarily. Some PDF viewers, including browser viewers, have limited Acrobat JavaScript support. Test the form in Acrobat and in any viewer your recipients are expected to use.




