Skip to main content
CalcBuilder logo

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.

...
List Manager

Build different lists for your site

Buy now!
...
Support/development 40 hours

With the peace of mind of having a professional team at your service (20% discount)

Buy now!