JavaScript pop-up that flags high numeric entries for review before continuing | XM Community
Skip to main content

Hi all! Does anyone have JavaScript for a pop-up message that displays if a respondent enters a number above a certain threshold that I consider unrealistically high? I want it to prompt them to double-check their entry before continuing, but I don’t want it to force them to change their answer.

 

Context: I have a constant-sum question asking respondents to enter annual spend in millions. Some respondents overlook the “in millions” part and enter values like 1,000,000 instead of 1. Other times, someone enters a number that feels extremely large, and we usually need to follow up and confirm it wasn’t a typo. It would be a huuuge time-saver to simply build a typo-check directly into the question.

 

I’d like the pop-up to appear if someone enters a number ≥500. It should only prevent them from continuing the first time it appears (i.e., after they’ve seen the pop-up, they are allowed to proceed regardless of whether they’ve changed their answer).

 

Has anyone implemented something like this? I’m open to switching to a matrix-table constant-sum if that would make it easier.

You could use this:

Qualtrics.SurveyEngine.addOnload(function() {
var confirmed = [];
this.getQuestionContainer().querySelectorAll(".SumInput>input,.choice-outer input").forEach(function(el,i) {
el.addEventListener("input", function(evt) {
this.value = Number(this.value.replace(/\D/g,""));
if(this.value>=500 && !confirmed.includes(i)) {
confirmed.push(i);
if(confirm("Are you sure?")==false) this.value=this.value.slice(0,-1);
}
});
});
});