Default choice for drill down question using embedded data | XM Community
Skip to main content
Solved

Default choice for drill down question using embedded data

  • February 14, 2020
  • 8 replies
  • 507 views

Forum|alt.badge.img+1
Is it possible to set default choice(s) for a drill down question using embedded data? I've done it for a multiple choice question using the following JS: if("${e://Field/myfield}" == "Yes") this.setChoiceValue(1,true); if("${e://Field/myfield}" == "No") this.setChoiceValue(2,true); How do I adapt this for a drill down question (with four levels of drill down)?

Best answer by TomG

Yes, you can refer to each of drop downs based on their index: ``` var selects = jQuery("#"+this.questionId+" select"); selects.eq(0).val("2"); //Set first select value to 2 selects.eq(1).val("1"); //Set second select value to 1 ```
View original

8 replies

Akdashboard
Level 4 ●●●●
Forum|alt.badge.img+6
  • Level 4 ●●●●
  • 488 replies
  • February 14, 2020
I am curious if someone replies with an answer. I've had this issue in the past and have had to use display logic and default choice selection to solve this. I'd then pipe the selected answer from each choice to the same embedded data variable in order to combine the data and work from a single data source.

Forum|alt.badge.img+1
  • Author
  • 12 replies
  • February 15, 2020
Do you mind explaining your work around further - I don't quite understand what you mean about the combo of display logic and default choice. Hopefully someone knows the answer to my question but in case they don't I'll have to rethink what I'm doing!

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 5938 replies
  • February 16, 2020
You can use JavaScript to set the value of the select(s). Here is how you could do it for a single MC drop down: ``` var select = jQuery("#"+this.questionId+" select"); if("${e://Field/myfield}" == "Yes") select.val("1"); if("${e://Field/myfield}" == "No") select.val("2"); ```

Forum|alt.badge.img+1
  • Author
  • 12 replies
  • February 16, 2020
Thanks @TomG that's working perfectly for a single dropdown MC, but I'm not sure how to adapt it for use in a drilldown. I want to set 4 layers of drilldown but I'm not sure how to reference the different levels & choices. Is that possible?

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 5938 replies
  • Answer
  • February 17, 2020
Yes, you can refer to each of drop downs based on their index: ``` var selects = jQuery("#"+this.questionId+" select"); selects.eq(0).val("2"); //Set first select value to 2 selects.eq(1).val("1"); //Set second select value to 1 ```

Forum|alt.badge.img+1
  • Author
  • 12 replies
  • February 17, 2020
> @TomG said: > Yes, you can refer to each of drop downs based on their index: > ``` > var selects = jQuery("#"+this.questionId+" select"); > selects.eq(0).val("2"); //Set first select value to 2 > selects.eq(1).val("1"); //Set second select value to 1 > ``` Thank you @TomG! That is so, so helpful. Edit: I did not mean to accept my own comment as an answer but now I can't remove it :D

Forum|alt.badge.img
  • 3 replies
  • December 11, 2020

How do you know
https://www.qualtrics.com/community/discussion/comment/22276#Comment_22276How can you set value based on the index if a drill-down drop menu changes based on the previous drop-down selection? Can you use the "text" display on the dropdown as the value instead of its index?

Thank you!


TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 5938 replies
  • December 12, 2020

How can you set value based on the index if a drill-down drop menu changes based on the previous drop-down selection? Can you use the "text" display on the dropdown as the value instead of its index?

The index (e.g., eq(0)) refers to the drop-down, not the options in the drop-down. The values are the choice ids, and they are always associated with the same choice (text) regardless of how many choices are displayed.