Skip to content

Instantly share code, notes, and snippets.

@penalosa
Created January 19, 2022 23:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save penalosa/aef2c0ee7a6020b5976cb7883e00890c to your computer and use it in GitHub Desktop.
Save penalosa/aef2c0ee7a6020b5976cb7883e00890c to your computer and use it in GitHub Desktop.
Support inline dropdown in Qualtrics
Qualtrics.SurveyEngine.addOnload(function()
{
this.hideChoices();
const alreadySelected = this.getSelectedChoices()[0]
this.getQuestionTextContainer().innerHTML = this.getQuestionInfo().QuestionText.replace(
"{{dropdown}}", "<select required name=\""+this.getQuestionInfo().QuestionID+"\" id=\""+this.getQuestionInfo().QuestionID+"-select\"><option value=\"\" disabled "+(!alreadySelected?"selected":"")+" hidden></option>"+Object.values(this.getQuestionInfo().Choices).map(c => "<option "+(alreadySelected ==c.RecodeValue?"selected":"")+ " value=\""+c.RecodeValue+"\">"+c.Text+"</option>").join("\n")+"</select>"
);
this.getQuestionTextContainer().querySelector("select").addEventListener('change', e => {
let option = e.target[e.target.selectedIndex]
this.setChoiceValueByRecodeValue(option.value, option.text)
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment