Hard coding text in Matrix questions | XM Community
Question

Hard coding text in Matrix questions

  • 12 May 2020
  • 1 reply
  • 24 views

In a Matrix Text Entry question, is it possible to hard-code text under each text box answer? Or, is it possible to have an entire column (scale point) pre-populate with text that can't be erased?
My problem/use case: I'd like to be able to give respondents example answers that can't be removed. More specifically, for each question I'm asking about the respondent's institution I'd like to be able to show the answer from my own institution... Would look something like this:
Screen Shot 2020-05-12 at 2.20.03 PM.png


1 reply

Userlevel 7
Badge +27

Hi there, if you still need, this is possible by using Default Choices and then setting the input fields to readonly. First, create a Matrix question and set it to be Text Entry. Then, add the Default Choices that should be set to readonly. Finally, add the below to the question's JavaScript in the OnReady section. In the below example, I set it so that for rows 1,2, and 3, the first column will be set to readonly.
var qid = this.questionId;

var cell_1_1 = 'QR~'+qid+'~1~1~TEXT';
var cell_2_1 = 'QR~'+qid+'~2~1~TEXT';
var cell_3_1 = 'QR~'+qid+'~3~1~TEXT';

document.getElementById(cell_1_1).setAttribute('readonly', 'readonly');
document.getElementById(cell_2_1).setAttribute('readonly', 'readonly');
document.getElementById(cell_3_1).setAttribute('readonly', 'readonly');
The input ID's are QR~QID~Row#~Column#~TEXT so update the Row# and Column# as needed based on which cells should be readyonly.

Leave a Reply