Skip to content
  • There are no suggestions because the search field is empty.

Survey scripting: beyond point-and-click logic

When point-and-click logic isn't enough: add a few lines of code for custom scoring, your-own-words validation, real-time quality control, and surveys that adapt on the fly.

Centiment's visual logic builder handles most of what a survey needs: showing and hiding questions, skipping people based on their answers, setting quotas, piping answers into later questions, shuffling options, marking fields required. Most of the time, that's all you'll ever touch.

Every so often, though, you want something the menus just don't have a checkbox for. A score that adds up ten different answers. An error message written in your own voice. A question that's only required when it actually matters. Copy that reads differently on a phone. That's where Scripting comes in.

Scripting lets you drop a little JavaScript into a survey and have it run while someone takes it. The script watches answers as they come in and responds through a simple cs API. Nothing to install, no servers to wire up. Everything below is something the standard controls can't do on their own.

At a glance: visual logic vs. Scripting

What you want to do Point-and-click logic With Scripting
Require an answer ✅ On / off per question Conditional — required only when it matters
Validate input Answer-exists check, one generic message Any rule, your own error message, non-blocking warnings, cross-question checks
Compute a score or total ❌ Export and calculate in a spreadsheet ✅ Scores, sums, NPS roll-ups, tiers — live, stored as variables
Personalize question text Pipe in an answer or variable Rewrite titles, options, and matrix labels at runtime
Adapt to device, language, or link source ✅ Device-, language-, and URL-parameter–aware copy
Show / hide questions & options ✅ Preset display, skip & choice logic ✅ Live, answer-driven — plus carry-forward into later questions
Control navigation Skip to a later question ✅ Auto-advance, skip-to, block "Next" until ready, back-nav cleanup
Catch speeders / low quality ❌ Review after the survey ✅ Detect by timing in real time; tag or disqualify on the spot
Tag responses for segmentation ✅ Add labels like speeder or engaged during the survey
Randomize options Shuffle (re-randomized on each page load) Seeded per-respondent shuffle — same order on reload
Run an A/B split ❌ No native control ✅ Deterministic bucketing
Custom ending + redirect Standard end screens & quotas ✅ Script-driven complete / disqualify / over-quota, each with a custom redirect URL
Format numbers (currency, %) ✅ Clean on-screen formatting in any text

 

1. Validation in your own words, and your own rules

Before: You had one lever: required, on or off. It showed the same generic "this field is required" message every time, and all it really checked was whether the respondent typed anything at all.

Now: You can check whatever you want, and word it however you want. Or skip the hard stop entirely and just nudge people with a warning they can click past.

  • "Your numbers need to add up to 100%."
  • "Looks like a personal email. Can you use your work one?"
  • "That's higher than most people report. Sure that's right?" (a warning, not a block)
  • Checks across questions: "Your end date can't come before your start date."
cs.onValidate((qid, value) =>   
value > 0 ?
{ valid: true } :
{ valid: false, message: 'Please enter a number above zero.' }
);

It's the difference between a form that takes whatever people type and one that quietly catches the bad stuff before it ever reaches your results.

2. Live scoring and calculations

Before: There was no way to do math across questions. If you wanted a score, you exported the data and worked it out in a spreadsheet afterward.

Now: Add up Likert items, roll up an NPS number, weight a quiz, or sort people into tiers, then save the result as a survey variable. Once it's a variable, you can pipe it into a later question, branch on it, or send it to your export with everything else.

  • Quiz and assessment scores you show the respondent at the end.
  • A satisfaction index pulled together from a handful of rating questions.
  • "High value / medium / low" buckets, worked out on the fly and used to route people.

You can even watch a score climb as someone types, and show it back to them formatted as a dollar figure or a percentage.

3. Content that adapts to each respondent

Before: Piping let you slot a past answer or a variable into your question text. Handy, but the words around it stayed put.

Now: You can rewrite the wording itself, question titles, answer options, even matrix rows and columns, based on anything you know about the person answering.

  • Different copy by device: "Tap your choice" on a phone, "Click your choice" on a laptop.
  • A title that greets them by name: "Welcome back, Jordan. Let's pick up where you left off."
  • Phrasing that fits the language, not just a word-for-word translation.
  • Grab a value straight from the survey link, a utm_source or a CRM ID, and tailor the experience to where someone came from. You don't even have to set up a variable for it.

4. Smarter flow control

Before: Display and skip logic could show, hide, or jump, but only along the paths you mapped out ahead of time.

Now: The survey can react in the moment:

  • Conditional required — make a question mandatory only when it counts, like asking for a comment only after a low rating.
  • Answer-driven options — carry the brands someone picked earlier into a later matrix and drop the rest.
  • Auto-advance — move to the next question on its own once a clear answer is in.
  • Hold "Next" until they're ready — keep the button off until the respondent has written enough, ticked the box, or met whatever bar you set.
  • Skip ahead and clean up on the way back — jump to a later section, or reset a calculated value when someone steps backward.

5. Built-in quality control

Before: Spotting low-effort responses, the speeders and the straightliners, was cleanup you did once the data was already in.

Now: You can catch it as it happens and act on it right away:

  • Speeder detection — see how long someone spent, and flag or disqualify anyone who raced through.
  • Per-question timing — know how long each question took, including time spent going back and forth.
  • Tags — stick labels like speeder, engaged, or mobile-user on a response so it's easy to slice later.
  • End it on your terms — mark someone complete, disqualify them, or send them down an over-quota path, each with its own redirect URL.
cs.onComplete(() => {   
if (cs.elapsed() < 30000) { // finished in under 30 seconds
cs.addTag('speeder');
cs.disqualify({ quality: true });
}
});

6. Reproducible randomization and simple experiments

Before: You could shuffle options, but the order changed on every reload, and there was no clean way to run an A/B test, so people fell back on random tricks.

Now: Seeded randomization ties the shuffle to each respondent, so anyone who reloads sees the same order they saw before. That consistency is exactly what you want when you have to stand behind the data later. And since you can bucket people in a predictable way, A/B splits stop being a coin toss.

Getting started

Open a survey, head to the left menu, and click Scripting. The editor autocompletes the whole cs API as you type. If you'd rather just say what you want in plain English, like "disqualify anyone under 18 and thank them," the built-in AI assistant will write the script for you. As you test, a live preview debugger shows what's actually happening: console output, every event that fires, and the current state of your answers and variables.

Use a per-question script for behavior tied to one question, and the survey-level script for anything that spans the whole survey, like scoring at the end.

Good to know

  • It runs safely in the respondent's browser. Scripts are sandboxed: they can read and shape the survey, but they can't reach the page, cookies, or the network. And if a script trips on an error, the survey carries on without it. The respondent never notices.
  • Labels stay plain text. Any wording you rewrite shows up exactly as written, with formatting stripped out, so respondents always get clean, safe copy.
  • No outside calls yet. Scripts work within the survey itself. Reaching out to a third-party API mid-survey is on our roadmap, but it isn't here yet.
  • Built for real data. Anything a script changes about flow, required fields, or completion gets re-checked on our servers, so your results hold up even when a connection is shaky or someone tries to game it.

So if you've ever run into the edge of the logic builder, a calculation it couldn't do, a message it wouldn't let you write, a rule that hangs on timing or device or someone's exact words, Scripting is how you get past it.