PDF Editing Issues

Create a Toggle Button With Text, Color, and Date in Adobe Acrobat

Algirdas JasaitisAlgirdas Jasaitis Nov 19, 2026 870 views

Question details

Create a PDF form button that switches its color and text and records when it was pressed.

Create a Toggle Button With Text, Color, and Date in Adobe Acrobat
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.
Before you start

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.

Solution 1Recommended

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.

1
Create the form fields

In Acrobat, open All tools > Prepare a form. Add or select a button, then add a text field named datefield for the timestamp.

2
Set the button appearance

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.

3
Add the button action

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()); }

4
Save and test the form

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.

Add a JavaScript toggle to the Acrobat form button
Use the exact field name: Replace datefield in the script with the actual name of your timestamp field. The script skips the timestamp update if it cannot find that field. PDF viewers vary in their support for Acrobat JavaScript, so test the form in Acrobat.
Free Microsoft Office alternative

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.

View PDFs alongside your other documents in one suiteCompatible with Microsoft Word, Excel, and PowerPoint formats, including DOCX, XLSX, and PPTXFamiliar interface makes migration from Office easierFree, lightweight option for everyday document work
microsoft office alternative - wps office

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.