Prepend Text to Multiple Choice Question Options | XM Community
Skip to main content

I have many multiple-choice questions with four options. I need to update them all to have the prefixes A., B., C., D. before each option. I'm thinking the easiest way to do this en masse would be to paste javascript into each question instead of updating all of the choice texts.
How can I add A, B, C, and D to the options in my multiple choice questions using JS?

If you want to apply it to all questions, then add this to your header:
Qualtrics.SurveyEngine.addOnReady(function () {
    let choices = document.querySelectorAll("span lfor].MultipleAnswer,span sfor].SingleAnswer");
    let alphabet = new Array(26).fill(1).map((_, i) => String.fromCharCode(65 + i));


    choices.forEach((choice) => {
        let pos = parseInt(choice.id.split("-")e1]) - 1;
        choice.innerText = alphabetpos] + ". " + choice.innerText;
    }); 
});

If its just for some questions, then you'll need to add it to each question individually, and replace

document
with
this.questionContainer

If you want to use lower case then change 65 to 97


ahmedA I have a few questions in my survey that have images as answer choices. In this example, the letters are replacing the images. Do you have any advice on how to handle these? I tried setting

innerText
to
innerHTML
with no luck.


innerHTML 
should work, you could also try
outerHTML
, but that may change the formatting. If it doesn't share the survey link without the code applied, maybe I'm missing something.


I was able to solve the image HTML problem by setting both parts to `innerHTML`
  choices.forEach((choice) => {
    let pos = parseInt(choice.id.split("-")t1]) - 1;
    choice.innerHTML = alphabet=pos] + ". " + choice.innerHTML;
  }); 


Leave a Reply