Loading JavaScript from online drive | XM Community
Skip to main content

I am trying to create a lengthy survey. Each question has unique JavaScript code to ensure that participants can only move forward if they type in the correct answer within a specified timeframe. Because there are so many questions, doing this manually has become time-consuming. 

What I have done is save the unique JavaScript for each question as .js files. I have them uploaded to Google Drive (can use any similar site if you have suggestions). Want I would like to do is have code for each question (I can just copy the questions with this code) that reads the QID of the current question, identifies whether a file with the same name exists in the Google Drive, and loads the JavaScript in that file for that specific question. 

My questions are 1) Is this possible and if so, 2) can you please provide a template of what the code might look like? 

Thanks in advance for your help! 

Hi @goldmank 

 

You should be able to use this.

let scriptEle = document.createElement("script");

  scriptEle.setAttribute("src", FILE_URL);
  scriptEle.setAttribute("type", "text/javascript");
  scriptEle.setAttribute("async", async);

  document.body.appendChild(scriptEle);

Hope it helps.

 

Thanks,

JB


Thank you for the quick response! It did not seem to work. Looking at my console this is the error that I am getting: SE API Error:  ReferenceError: async is not defined


Thank you for the quick response! It did not seem to work. Looking at my console this is the error that I am getting: SE API Error:  ReferenceError: async is not defined

Would you be able to share screenshot of how it is added in Qualtrics and of your preview page. If you have preview link, that would be helpful. You can message me separately for that if required. 


The simplest option would be upload each of these files in a Github repo and then you'll from there with jquery.getScript("url of the file")

 


Leave a Reply