Embedding Text From Github in Survey Question Text | XM Community
Solved

Embedding Text From Github in Survey Question Text


Dear Qualtrics Community,
I'm new to HTML & Javascript and haven't been able to find a way to do this:
I need to embed text from a .txt file (or a .js file, if that's easier) on my github page into my survey question text. Importantly, I don't want an iframe – the text from github should embed seamlessly into the surrounding question text in Qualtrics. I've tried jQuery.get and ajax, but haven't gotten them to work, so I worry I might be getting something fundamentally wrong.
This is what I've tried so far:
in HTML, and the following Javascript:

Qualtrics.SurveyEngine.addOnload(function()

{

    var url = '
https://raw.githubusercontent.com/example_URL.txt';
   jQuery.get(url, function(data) { 

       $('#GithubText').text(data);

     });

});

(This is an approach I copied from here)

As mentioned above, I'm a complete beginner – so any ideas on how to get this working would be much appreciated!! Thank you!

icon

Best answer by TomG 5 July 2020, 23:01

View original

4 replies

Userlevel 7
Badge +27

Change $('#GithubText') to jQuery('#GithubText')

Thanks so much Tom! This got it to work – but there's still a problem unfortunately. After this worked in my experimental survey, I wanted to try it out in my actual survey. There, however, it didn't work (despite copy&pasting everything).
What's even stranger, I then went back to my experimental survey (where your solution had worked) and duplicated the question inside that survey ("copy question") – just to find that the two questions behave differently. This morning, the piping in of text from github worked in both these "twin" questions, then it only worked in the original question, now it only works in the duplicate.
Do you have any idea as to what might be causing this unsteady behavior a) across surveys and b) within a survey?
Could b) perhaps be due to cross-referencing/interfering between questions (I've already tried changing javascript variable names in the duplicate question though)?
Thanks again for your help!

Userlevel 7
Badge +27

If the questions are on the same page it would be a problem because the id GithubText wouldn't be unique. That would explain why it only works on one random question but not the other.
When you copied to your other survey did you remember to also add the span with the id GithubText?
The only other thing that looks strange in your original post is the quotes on id="GithubText" but I was thinking that was just a copy/paste problem.

Tom, thank you so much! The quotes were indeed the problem – not quite sure what had happened there. Now it's working perfectly. Thanks so much for all your helpful comments in this forum!

Leave a Reply