How to extract the text value(s) selected from a drill-down in JS? | XM Community
Skip to main content
Question

How to extract the text value(s) selected from a drill-down in JS?

  • August 25, 2021
  • 2 replies
  • 167 views

cdarabos
Forum|alt.badge.img+1

I'm trying to capture the actual text values of the selected options of in a drill-down question.
Qualtrics.SurveyEngine.addOnPageSubmit(function() 
{
    var location = jQuery("#"+this.questionId+" select").eq(0).val();
}

location
has an integer value of the position in the list. Calling
jQuery("#"+this.questionId+" select").eq(0).text()
returns the full list of all options as a string.
How do I only get the one item that was select as the text of the option selected?
Thank you!

2 replies

grahulp5
QPN Level 3 ●●●
Forum|alt.badge.img+13
  • QPN Level 3 ●●●
  • August 26, 2021

Try this:
jQuery('#"+this.questionId+"').find(":selected").text()


JeremyK
Level 3 ●●●
Forum|alt.badge.img+7
  • Level 3 ●●●
  • August 31, 2021

I agree with grahulp5 save for one change: I don't think that jQuery is gonna work, something looks funny about the apostrophes and quotes. If I may suggest a small amend, here's what I'd use.
jQuery('#' + this.questionId).find(":selected").text()
This returns the selected dropdown value as a string (null when page loads, string value upon reload/revisiting). Please drop a comment here if this doesn't give you exactly what you're looking for.