Presumably I can do something similar in Qualtrics with Question JavaScript, but I'm having trouble getting started. I set up a simple JavaScript validation for a question (though I know it could be done instead using built-in options) to make sure I've got the basics right; see below. It catches the error when the entry is less than 3 and displays an alert, but the survey still progresses to the next page after the respondent accepts the alert.
My JavaScript knowledge and experience is limited to the context of the online survey software I used prior to Qualtrics, and I can't tell what I'm overlooking even after searching the community and the wider internet. Any suggestions?
Qualtrics.SurveyEngine.addOnPageSubmit(function()
{
var q1 = parseInt(document.getElementById('QR~QID3').value, 10),
msg = 'Please enter a number greater than 2.';
if (q1 < 3)
{
alert(msg);
document.getElementById('QR~QID3').focus();
return false;
} else {
return true;
}
});
Best answer by TomG
View original