Trying to set embedded data from radio or dropdown response | XM Community
Skip to main content

Trying to set embedded data from radio or dropdown response

  • January 2, 2020
  • 7 replies
  • 136 views

Forum|alt.badge.img
Hello, I am trying to get the numerical value of a response (1 for first choice, 2 for second and so on) so I can use it to set a specific email. Here is my code so far: Qualtrics.SurveyEngine.addOnload(function() { document.getElementbyID("QID6").style.display="none"; this.questionclick = function(event,element) { console.log(event, element); if (element.tagName == 'SELECT') { var choiceNum = element.value if (choiceNum == 1) { Qualtrics.SurveyEngine.setEmbeddedData("SBAEmail","email@email.com"); } else if (choiceNum == 2) { Qualtrics.SurveyEngine.setEmbeddedData("SBAEmail","email2@email.com"); } else if (choiceNum == 3) { Qualtrics.SurveyEngine.setEmbeddedData("SBAEmail","email3@email.com"); } } } }); This only works for the first reponse. What am I missing here?

7 replies

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • January 2, 2020
You and @TeachMeQualtrics just asked the same question. You are trying to do it the hard way. Try this: ``` Qualtrics.SurveyEngine.addOnPageSubmit(function() { var list = { 1: "emailAddress1", 2: "emailAddress2", 3: "emailAddress3" }; Qualtrics.SurveyEngine.setEmbeddedData("SBAEmail", list[jQuery("#"+this.questionId+" select").val()]); }); ```

Forum|alt.badge.img
  • Author
  • January 2, 2020
That looks much cleaner. Why use addOnPageSubmit over addOnload?

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • January 2, 2020
I> @maindanger said: > That looks much cleaner. Why use addOnPageSubmit over addOnload? > It is cleaner and more efficient to set the embedded data field once instead of each time the question is clicked.

Forum|alt.badge.img
  • Author
  • January 2, 2020
What does the "#" and "select" mean in the jQuery? Im not a programmer but Im trying to learn. THank you for your help.

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • January 3, 2020
> @maindanger said: > What does the "#" and "select" mean in the jQuery? Im not a programmer but Im trying to learn. THank you for your help. jQuery uses CSS-style selectors. # means it is an id (e.g., #QID1) and select is an html tag. So, the selector selects the select elements inside the current question.

Tom, Thank you so so much for your help and time. We did not realize we were both posting! ! We have tried your code, entering the question query, ! with a matching action, but are unable to make the action work. I tried just using QID40, or just 40. I know this must be something simple I am missing, but i spent all night trying to make it work. Thank you, we owe you one for your assistance.

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • January 3, 2020
> @TeachMeQualtrics said: > Tom, Thank you so so much for your help and time. We did not realize we were both posting! ! > We have tried your code, entering the question query, > ! > with a matching action, but are unable to make the action work. I tried just using QID40, or just 40. I know this must be something simple I am missing, but i spent all night trying to make it work. > Thank you, we owe you one for your assistance. Remove QID40. The value of this.questionId is the question id (i.e., QID40). Also, the JS is written for a select (aka drop down). You'll have to change the selector if you use radio buttons: ``` jQuery("#"+this.questionId+" input:checked").val() ```