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)?
Page 1 / 1
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.
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!
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");
```
```
var select = jQuery("#"+this.questionId+" select");
if("${e://Field/myfield}" == "Yes") select.val("1");
if("${e://Field/myfield}" == "No") select.val("2");
```
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?
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
```
```
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
```
> @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
> 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
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!
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.
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.