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
documentwith
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
innerTextto
innerHTMLwith no luck.
innerHTMLshould 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
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.