JavaScript to pre-select an option based on query string/embedded data | XM Community
Skip to main content

Hello everyone!

I need a solution to a new experience we are creating for our Email surveys. 

We are going to send the link in the response from our Customer Service team so we can send only one mail instead of 2. So we won’t be using the Qualtrics’ mailer. 

The HTML we are going to use will ask the first question within the email body, so we are seeking a similar behavior as the one native from Qualtrics with the embedded questions in emails. 

The question is a Yes/No question. So when the user clicks wether on Yes or No, I need the survey to open in the browser and the option to be pre-selected in that first question. Is this possible?

We are thinking on including the response in the URL and then executing some JavaScript. So the action in both buttons would be something like link?response={value} and then with JS preselect the option in the survey. Would this be the best option? how should the JS look like? 

Or is there another best option?

Thanks in advance!

Hello everyone!

I need a solution to a new experience we are creating for our Email surveys. 

We are going to send the link in the response from our Customer Service team so we can send only one mail instead of 2. So we won’t be using the Qualtrics’ mailer. 

The HTML we are going to use will ask the first question within the email body, so we are seeking a similar behavior as the one native from Qualtrics with the embedded questions in emails. 

The question is a Yes/No question. So when the user clicks wether on Yes or No, I need the survey to open in the browser and the option to be pre-selected in that first question. Is this possible?

We are thinking on including the response in the URL and then executing some JavaScript. So the action in both buttons would be something like link?response={value} and then with JS preselect the option in the survey. Would this be the best option? how should the JS look like? 

Or is there another best option?

Thanks in advance!

@Ricmarug Yes, you can use that for inline survey question but keep in mind that email don’t usually allow script execution. So your personal-link?response=yes and personal-link?response=no must already been made and attached to the buttons. (i.e make 2 version of the link and put it in the email button, not click button to make the link)

Hope this helps


Hello @dxconnamnguyen!

Thank you for your reply. 

That’s exactly what we are planning to do. We’ll have the two versions with the two possible options in the query string. 
But what I need to know is how to pre-select the options on the survey based on the query string parameter. 

I mean, when I click Yes or No from the email, it’ll take me to the survey with that value in the URL. How can I preselect that option in the survey so the user don’t need to select it again?

 


@Ricmarug

Have you tried using Q_PopulateResponse? 

https://www.qualtrics.com/support/survey-platform/survey-module/survey-flow/standard-elements/passing-information-through-query-strings/#HowToQ_PopulateResponse

 

Hope this helps!


It worked perfectly, @Deepak. I didn’t know that one. Thank you very much!!

Quick question on this. Is it possible to change the name of that parameter in the URL? I tried adding a name of my own and then assigning that value to the Q_PopulateResponse embedded data in the survey flow before the question but it didn’t work. 

Something like this: 

{survey_link}?response={QID17":"1"}

 


@Ricmarug 

No, you cannot change that name unfortunately as it is Qualtrics survey Metadata.


Leave a Reply