How can I select a radio button in a survey based on a user click | XM Community
Skip to main content

I have 2 icons on a web page and based on what a user clicks, I need to have a choice selected in a survey. I have looked here, but it's not doing exactly what I need.
https://www.qualtrics.com/support/website-app-feedback/intercepts-tab/edit-intercept-section/action-set-options/adding-event-tracking-triggering/

Hey Prakash! Can you share a preview of your survey so I can see what you're seeing? It'll make the process go much faster! Just to get things straight, when a user clicks on icon A, you want choice X to be selected, and likewise if they click on icon B, you want choice Y to be selected. Are the question choices you're wanting to be selected on the same page? They don't have to be, just changes the process a touch. Thanks!


Hi Jeremy
Thanks for your help. Initially there will be a 'Happy' and a 'Sad' button on a page. When. the user clicks on either the survey opens and I need the Happy or Sad choice in the survey to be pre-populated.
This is the code I tried.
Qualtrics.SurveyEngine.addOnload(function() {
if (window.location.hash == "#happy") { 
document.getElementById("QID1-1-label").classList.add('q-checked');
}
});
I also tried to capture the happy/sad variable in an embedded value and set based on that
Step1.pngStep2.png
Here are a couple of screenshots:


Well, I was going to go a different direction with this, but something you said in your response sparked an idea. I read about query strings a while back, basically let's you pass parameters to your survey. I use them a ton in testing variables, but in this case, you could pass a parameter Emotion and set the embeddedData equal to happy when #happyButton is clicked vs "sad" if they chose #sadButton. Was this what you had tried earlier to capture based on embeddedData?


Yes, I am able to capture the value of Userclick from the page and set it as an embedded value. But the js is not recognizing the value.
Qualtrics.SurveyEngine.addOnload(function() {
console.log("from QL script " + Userclick);
if (Userclick == "happy") {
jQuery( "input[name='QR\\~QID1']:nth(0)" ).prop('checked', true); 
}
});


That's a bit of an odd way to grab the element . If you want to use jQuery, try something more like
jQuery('#QR\\\\~QID1\\\\~1')
source: # jQuery API documentation
Breaking this down:

  • The pound sign is looking for a specific element

  • The double backslashes(\\\\) are escaping the tilda(~)

  • If you Inspect Element on your matrix table single answer, your Happy should be 'QR~QID1~1' and your sad 'QR~QID1~2' (if you haven't added/deleted any radio buttons above that.

Give that a shot!


Leave a Reply