Locking a text field after the respondent has provided an answer | XM Community
Skip to main content

Hello,
I have been trying to include some JS code to lock the text field after a response has been entered, but I have only managed to lock the text field altogether (i.e. respondents just can't enter any text). This is the code I tried, which I found on a different thread:
Qualtrics.SurveyEngine.addOnload(function() {
jQuery("#"+this.questionId+" .InputText").prop("readonly", true);
});
I tried different ways to modify it to become "read only" as long as not empty, but to no success. Does anyone have any suggestions?
Many help in advance for any assistance!
Silvina

You can use this:
Qualtrics.SurveyEngine.addOnload(function () {
    if (this.getChoiceAnswerValue().length) {
        this.questionContainer.querySelector(".InputText").disable();
    }
});


Thank you for the quick response!
I tried the code, but it still makes the text field available to add or remove or change the answer.
This question is used in the Display Logic of three following questions (basically, depending on the respondent's answer, they see one of three following questions). Do you think it still makes the text field available because of that?


No that should not cause it to be editable. The issue could be that the addonLoad is not getting executed, because the page isn't loading again. Which could happen due to how the broswer is handling the back button. See this demo, its working on Firefox and Chrome, but not on Vivaldi.
What I would recommend is that you pin your answer to the top of the next page and disable the back button. See this post for details.


Thank you for the resources! This is very helpful


Leave a Reply