Default text for dropdown list | XM Community
Solved

Default text for dropdown list

  • 28 September 2020
  • 5 replies
  • 228 views

Badge

I have "Autoadvance on Questions" and "Autoadvance on pages" enabled on my survey. For one of the questions (dropdown list), I'd like to show default text "select one". When i use the code below, the autoadvance gets in the way and submits the survey before user has a chance to actually select an answer. What code should I use?
Qualtrics.SurveyEngine.addOnReady(function()
{
/*Place your JavaScript here to run when the page is fully displayed*/
 jQuery("#"+this.questionId+" select").find("option:eq(0)").text("Select one").attr("selected","disabled",true);
});

Thanks.

icon

Best answer by TomG 28 September 2020, 22:46

View original

5 replies

Userlevel 7
Badge +27

Try this:
Qualtrics.SurveyEngine.addOnload(function() {
jQuery("#"+this.questionId+" select").find("option:eq(0)")
.text("Select one").prop({"disabled":true,"selected":true});
});

Badge

This worked. Thank you so much Tom!

Badge +2

Hi, ahmedA TomG Michael_Cooksey,
The above answer works fine. However, if a user selects a value from the dropdown and proceeds to the next question and then revisits the previous question consisting of the dropdown to verify the value which was previously selected then in that case it will show "Select" as a selected value in the dropdown instead of the actual value which was previously selected.
Could you please let me know if there is a solution for this scenario as well?

Userlevel 7
Badge +27

https://community.qualtrics.com/XMcommunity/discussion/comment/46599#Comment_46599Pipe the selected answer into the JS. If it isn't empty, it has been previously selected.

Badge +2

Thanks for your reply.
I have done something like the below to make it work
var prevSelected = jQuery("#"+this.questionId+" option:selected").length;
if (prevSelected !== 1) {
jQuery("#"+this.questionId+" select").find("option:eq(0)").text("Select one").prop({"disabled":true,"selected":true});
}


Leave a Reply