Use JavaScript to take in Embedded Data to Set Embedded Data | XM Community
Skip to main content
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.
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("<")));`
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