How can I pre-fill text box responses and lock them to prevent editing? | XM Community
Skip to main content

Hi all,

 

I am trying to show my respondents some additional text for each option shown in a side-by-side question (SEE SCREENSHOT BELOW).

I cannot add this directly to the first column where the options are listed, as the options are carried forward from a previous question.

My approach has been to add a second column with text boxes, and use the default choices function to populate the corresponding text that I want to show for each option. I want the second column to effectively be an extension of the first, rather than something for the respondent to edit.

However, as it stands, I do not know how to ‘lock’ the text box so that this cannot be edited (or whether this is at all possible). Can anybody suggest how this could be done? Or any other approaches?

 

Thanks!

 

 

Hi @juanav ,

I believe you are using the Side by side structure and you want to disable the text area in the  second column , if that is so you can achieve the same using below code :

 

Qualtrics.SurveyEngine.addOnload(function()
{
/*Place your JavaScript here to run when the page loads*/

});

Qualtrics.SurveyEngine.addOnReady(function()
{
const textarea = document.querySelectorAll('ltype=text]');

const disabtextCSS = `
background-color: #f0f0f0;
color: #999;
cursor: not-allowed;
`;


textarea.forEach(area => {
area.disabled = true;
area.style.cssText = disabtextCSS;
});


});

Qualtrics.SurveyEngine.addOnUnload(function()
{
/*Place your JavaScript here to run when the page is unloaded*/

});

Hope this resolves your query😊!!


Thank you, @qualtrics_nerd ! You are a legend.

 

Juan


This is great!  I’m using it in a question, but this greys out every textbox on the page.  How would I modify the JS to apply only to the question in which it is housed?

 

Example: Question 2 is prefilling with embedded data.  I don’t want participants to alter the value, though I need it there for calculation purposes.  The next question (3) is a text box where I would like the user to fill in.  With above JS, the text box on question 3 is greyed out and not fillable.


Leave a Reply