This question is a "work in progress" in order to find a solution to the following previous question:
(1) ocgx2: Multiple Choice Questions up to three automatic trials
As suggested by @AlexG in a comment, one may have a look to JavaScript. Unfortunately I am a beginner with JavaScript and (La)TeX mixed codes and may be the present question is not well-posed.
Used tools: Linux OS + lualatex (TeXLive 2021) + Okular (which supports JavaScript and OCG/OCMG)
Unused tool: insdljs package (it not belongs to TeX Live and has to be installed separately)
Thus, the goal is here to adopt a step by step approach to try to understand what happens:
A. How to include JavaScript code into LaTeX source/macro? For example the following @AlexG's answer works with pdflatex but not with lualatex:
(2) What is the best way to insert document-level JavaScript in LaTeX documents
B. How to trigger JavaScript code with a button? Is \mediabutton from media9 package useful knowing it is only used for that functionality?
C. How to combine OCG/OCMG layers and JavaScript codes within a LaTeX source/macro? e.g. to make calculations and print them.
Besides these issues, could advanced users give me advices about documentation to read? I have remarked the following references, but how to start with and is there another document more relevant? (a) Acrobat JavaScript SDK (b) Developing Acrobat Applications Using JavaScript (c) PDF reference 1.7 (d) LuaTeX doc. (e) PdfTeX doc.
[hyperref][javascript][forms]– AlexG Feb 26 '22 at 20:05