Use JavaScript to take in Embedded Data to Set Embedded Data | XM Community
Skip to main content
Solved

Use JavaScript to take in Embedded Data to Set Embedded Data

  • November 13, 2019
  • 2 replies
  • 53 views

MSobotta
Level 4 ●●●●
Forum|alt.badge.img+25
I am passing Embedded Data which, which I then want to strip out the innerHtml and return it as new Embedded data. For example, I am passing the Embedded Data CatVar (< a h r e f ="/ l i n k">Top Category< / a >) to the survey and I want have just "Top Category" returned as the Category Embedded data. I have try a few dozen things and it is still not working. Helps! Survey Flow is: 1. All Embedded Data 2. JavaScript Block which also displays new Embedded Data JavaScript is as follows: <code>Qualtrics.SurveyEngine.addOnload(function() { /*Place your JavaScript here to run when the page loads*/ var jCatVar = "${e://Field/CatVar}"; var jCatVar2 = jCatVar.getElementsByTagName('a').innerHTML; Qualtrics.SurveyEngine.setEmbeddedData('Category', jCatVar2 ); });</code> Any help or further questions would be appreciated.

Best answer by NiC

Hey @MSobotta The code `jCatVar.getElementsByTagName('a').innerHTML;` will not work as this function works for HTML DOM elements. You can use the following code intead: `jCatVar.slice(jCatVar.indexOf(">")+1, (jCatVar.lastIndexOf("<")));`

2 replies

NiC
QPN Level 5 ●●●●●
Forum|alt.badge.img+27
  • QPN Level 5 ●●●●●
  • Answer
  • November 14, 2019
Hey @MSobotta The code `jCatVar.getElementsByTagName('a').innerHTML;` will not work as this function works for HTML DOM elements. You can use the following code intead: `jCatVar.slice(jCatVar.indexOf(">")+1, (jCatVar.lastIndexOf("<")));`

MSobotta
Level 4 ●●●●
Forum|alt.badge.img+25
  • Author
  • Level 4 ●●●●
  • November 14, 2019
Thanks, I will have to try that. I found a workaround on the front end that will only give me the data I need as .textContent.trim();