-->

Qualtrics: javascript - text entry

2019-09-21 01:05发布

问题:

I designed a Qualtrics survey which includes a text entry question. I used a form here and it contained 10 text entry boxes. I want participants to fill in at least 5 boxes (any 5 boxes out the 10 is okay). I don't think validation is a good idea because there are so many possible cases when you complete at least 5 text boxes out of 10. For every text box, both filling in it and not filling it are okay, as long as the total competed text boxes are no less than 5.

So I tried to do this through javascript. And here is my code but it cannot work. Please tell me how to change it. Thanks!!

Qualtrics.SurveyEngine.addOnload(function()
{

    //disables the next button on the page
    this.disableNextButton();

    var choicesID=this.getQuestionInfo().Choices.Key


    while (1)
    {
        var t=0
        for (var i=0;i<choicesID.length;i++)
        {
            choicetext=this.getTextValue(choicesID[i])
            if (choicetext.length != 0)
            {
                t=t+1
            }
        }

        if (t<=4) continue;
    }

    this.enableNextButton();
});

回答1:

Sorry to be the bearer of bad news, but you are way off. Your script has a number of errors, but the biggest problem is that it attempts to check how many have been answered when the question loads, which doesn't do you any good. You would need to keep an on-going count using an event listener.

I suggest an alternative approach that doesn't require any JavaScript or custom validation. Use a multiple choice, multiple select question with allow text entry / force response turned on for each answer option. Then just set the minimum number of answers to 5.