How do I set up a block of text that respondents can edit? | XM Community
Skip to main content

How do I create a section of text that respondents can edit? I want to show a written passage that’s several paragraphs long and give respondents the opportunity to edit only the first paragraph.

Hello ​@NatalieB,

Add a ‘Text Entry’ question to your survey. Update the header to include an instruction for the customer, such as: “Please edit Paragraph 1 only”.
Next, insert your paragraphs into the text entry box.

Then, add the following JavaScript, replacing the placeholder text ‘Paragraph’ with the actual content of the respective paragraph wherever it appears.

Qualtrics.SurveyEngine.addOnload(function() {
    // Get the text entry box
    var textBox = jQuery("#" + this.getQuestionContainer().id + " .InputText");

    // Pre-fill the text box with the passage
    var prefilledText = "Paragraph 1: Paragraph 1 content.\n\n" +
                        "Paragraph 2: Paragraph 2 content.\n\n" +
                        "Paragraph 3: Paragraph 3 content.";
    textBox.val(prefilledText);

    // Disable editing for all text except the first paragraph
    textBox.on("input", function() {
        var currentText = textBox.val();
        var paragraphs = currentText.split("\n\n");

        // Keep only the first paragraph editable
        if (paragraphs.length > 1) {
            paragraphs1] = "Paragraph 2: Paragraph 2 content.";
        }
        if (paragraphs.length > 2) {
            paragraphs 2] = "Paragraph 3: Paragraph 3 content..";
        }

        // Reassemble the text and update the text box
        textBox.val(paragraphs.join("\n\n"));
    });
});

 

I found this code online and tested it in my lisence, its working as expected.


Thank you, ​@Sachin Nandikol!

 

 


Leave a Reply