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

JavaScript to pre-select an option based on query string/embedded data

  • 23 October 2023
  • 5 replies
  • 130 views

Userlevel 4
Badge +16

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!

icon

Best answer by Deepak 30 October 2023, 14:39

View original

5 replies

Userlevel 7
Badge +20

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

Userlevel 4
Badge +16

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?

 

Userlevel 7
Badge +36

@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!

Userlevel 4
Badge +16

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"}

 

Userlevel 7
Badge +36

@Ricmarug 

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

Leave a Reply