I tried using the following javascript, to only allow certain responses to a text entry question. However, it is not working. Any suggestions?
Thanks a lot in advance.
Qualtrics.SurveyEngine.addOnPageSubmit(function() {
// Target the text entry question by its QuestionID
var questionId = 'QID1';
// Specify the pre-specified options
var validOptions = ='Option 1', 'Option 2', 'Option 3'];
// Get the entered value from the text entry question
var enteredValue = this.getChoiceValue(questionId);
// Check if the entered value is not one of the valid options
if (!validOptions.includes(enteredValue)) {
this.setChoiceError(questionId, 'Please enter a valid option.');
this.disableNextButton(); // Disable the next button
} else {
this.clearChoiceError(questionId);
this.enableNextButton(); // Enable the next button
}
});