Setting embedded data equal to a text entry multiple choice question value | XM Community
Skip to main content
Hi Qualtrics community,



I'm using OnPageSubmit to set an embedded data value equal to the value they typed into an open ended question if they did at all. But I'm not sure how to target the text input without using the direct ID. If I have to do that I will, but it's not good. Here's my example:



Q1

When did you start driving?

1: Year: _____

2: If it's easier to recall your age, you can specify that here: ______

3: I do not drive



How do I target the text input if they selected option 1 or 2?



This is what I'm imagining in my head:

If getChoiceAnswerValue == 1, then set xxx = ?????

Else If getChoiceAnswerValue ==2, then set xxx = ?????

Else set xxx = 0



I would prefer NOT to target by document.getElementById, since I'll be using this at least 16 times.
You can simply use piping code to punch in embed variable like below:-



${q://QID1/ChoiceTextEntryValue/1}

${q://QID2/ChoiceTextEntryValue/2}
The last time I tried that in the OnPageSubmit action, it didn't set any values. I thought it was because the ChoiceTextEntryValue didn't exist yet?



I'll try it again though.
Hello @Pete_L ,



Paste the below code in the js(OnReady) of the MC question:



var that = this.questionId;

jQuery("#"+that+" .InputText").on('blur',function(){

var s1 = jQuery("#"+that+" .InputText:eq(0)").val();

var s2 = jQuery("#"+that+" .InputText:eq(1)").val();

Qualtrics.SurveyEngine.setEmbeddedData("xxx", s1+s2);



});

Leave a Reply