What a script can do
A script is a small piece of JavaScript attached to one field. It runs as somebody fills the form in, on the web and on the phone alike, and it can do one of three things:
- work out the field’s value from other fields,
- decide whether the field is shown at all,
- check what has been entered and refuse it with a message.
Scripts run in a sandbox. There is no network, no storage, and no access to the page — a script can read the answers on the form in front of it and nothing else. That is deliberate: the same script has to give the same answer on a phone with no signal as it does in a browser.
Where to write one
Open a field in the form builder. Its properties include a Scripts area
with a slot for each of the three kinds. The editor lists every other field on
the form as a button; clicking one inserts value('that_key') for you, which
saves guessing at spelling.
The editor also has a Test control that runs the script against sample values and shows the result, so a script can be checked without filling the form in.
What the language supports
Ordinary JavaScript expressions and statements: const and let, if,
for, for…of, while, arrow functions, template literals, optional
chaining, ??. What is not there is anything that reaches outside the form —
no fetch, no window, no document, no localStorage, no import.
The functions available inside a script are listed in the script function reference.
Scripts and formulas
A Calculated field has a simpler alternative to a value script: a
formula, written like {reading_end} - {reading_start}. Formulas cover
arithmetic and a few functions and need no JavaScript. See Calculated fields
and formulas. Anything a formula
cannot express is a value script.