Default text for dropdown list | XM Community
Skip to main content
Solved

Default text for dropdown list

  • September 28, 2020
  • 5 replies
  • 424 views

Forum|alt.badge.img

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.

Best answer by TomG

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

View original

5 replies

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 5935 replies
  • Answer
  • September 28, 2020

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


Forum|alt.badge.img
  • Author
  • 3 replies
  • September 28, 2020

This worked. Thank you so much Tom!


Forum|alt.badge.img+2
  • 14 replies
  • May 31, 2022

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?


TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 5935 replies
  • May 31, 2022

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.


Forum|alt.badge.img+2
  • 14 replies
  • May 31, 2022

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