Skip to main content

CalcBuilder Tutorial

Calc Builder 6: the Javascript code

The JS Code screen adds client-side behaviour — things that should happen without a round-trip to the server: live totals as the visitor types, showing or hiding fields, custom validation, formatting.

JS Code editor

Hooks

The editor is split into event blocks:

  • JS functions — your own helper functions, loaded once.
  • Before / after the calculate button — run around the server calculation.
  • Reset button — run when the form is cleared.
  • Event code — bind to field change/keyup events for live updates.

Reading and writing fields

Use getCBFormValue(id) to read a field and the matching setter to write one (the field id is shown on the Form Fields screen). Combine JS for the instant feedback with PHP for the authoritative result.

If a value must be trustworthy (a price, a score that is stored or e-mailed) compute it in PHP — client-side code can be tampered with.

...
Support/development

Perfect for small code changes or to correct any bug at your site

Buy now!
...
CalcBuilder

Create dynamic calculators

Buy now!