# LaTeX PDF form: Detect CheckBox changed event

I use LaTeX to create a fillable PDF document. How can I detect that a \CheckBox has been clicked?

It seems to react only to onfocus={...}, not to onclicked={...} or onchanged{...}.

Do I need to register an EventListener in an insDLJS environment?

Code:

\documentclass{article}
\usepackage{hyperref}

\begin{document}
\begin{Form}
\end{Form}

\end{document}


The events have other names, in hpdftex.def I find onfocus, onblur, onmousedown, onmouseup, onenter, onexit. There is also onclick, but it seems to be implemented only for Pushbuttons.

Not every event makes really sense for check boxes, e.g. the mouse event seem to conflict with the checking.

\documentclass{article}
\usepackage{hyperref}

\begin{document}
\begin{Form}

\end{Form}
\end{document}


An alternative to hyperref is eforms (acrotex), which has more options (and also more documentation). See e.g. https://tex.stackexchange.com/a/390882/2388

• Thanks for your response. onenter and onexit are already triggered when the cursor hovers over the element (respectively leaves it). Onfocus would be more handy in that situation. I took a look into the eform documentation. There doesn't seem to be an onclick for the \CheckBox element either. Did I overlook something? – MPW Nov 5 '18 at 15:15
• By the way, onmousedown and onmouseup don't work, unfortunately. I'll probably have to solve this with onfocus and onblur, which is only partially satisfying. I'm still wondering if an EventListener code be added manully... – MPW Nov 5 '18 at 15:27
• \checkBox[\AA{\AAMouseDown{\JS{app.alert("Mouse Down!")}}}]{myCheck}{10bp}{10bp}{On} works fine for me with eforms. – Ulrike Fischer Nov 5 '18 at 15:44

The event you are looking for is called validate:

\documentclass{article}
\usepackage{hyperref}

\begin{document}
\begin{Form}

According to the hyperref documentation validate contains "JavaScript code to validate the entry", so using it as a general "changed" event might look like a hack, but in reality it generates a /V entry in the form fields additional actions dictionary. While this entry can be used for validation, that's only one possible use. It is specified for PDF 1.7 as a general "onchange" event:
The advantage of using validate instead of e.g. onmousedown is that validate still works if a user uses another input method, for example selecting the field using the keyboard instead of clicking it with the mouse.