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

Use JavaScript to take in Embedded Data to Set Embedded Data

  • 13 November 2019
  • 2 replies
  • 34 views

Userlevel 4
Badge +17
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.
icon

Best answer by NiC 14 November 2019, 19:17

View original

2 replies

Userlevel 7
Badge +27
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("<")));`
Userlevel 4
Badge +17
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();

Leave a Reply