Search code examples
javascriptqualtrics

Qualtrics-Allow respondent-entered zeroes to remain, but clear the rest


I have a Constant Sum question asking respondents to enter in a count of something, and directing them to enter 0 if None. So on the first load, I want the fields to be empty. I've used the code snippet provided by Qualtrics:

var inputs = $(this.questionContainer).select('input');

inputs.each(function (input) {
    if (input.value == 0) {
        input.value = '';
    }
});

However, if a respondent has entered 0, gone to the next question, and then returns to the previous question, then their entries are cleared along with the other default zeroes. Is there some way to modify the script to maintain the manually-inputted numbers if they return to a question?


Solution

  • You could set an embedded data field for each page at the beginning of the survey. then modify each page's code to be something similar to the following:

    var inputs = $(this.questionContainer).select('input');
    var pageFlag = "${e://Field/pageFlag}";
    
    if(pageFlag != 1){
        inputs.each(function (input) {
            if (input.value == 0) {
                input.value = '';
            }
        });
        Qualtrics.SurveyEngine.setEmbeddedData("pageFlag",1);
    }
    

    Unfortunately, each page would need it's own piece of embedded data and the code on each page would have to be customized. But it is possible.