Help! Javascript code to auto-continue to next question after clicking hyperlink | XM Community
Skip to main content

Hi all,

I am new to programming and could very much use your help.
For my study, I want participants to click on a hyperlink that opens a website in the same window. Upon clicking, I want the survey to automatically continue to the next question.

(Because ON the website, I embedded the Qualtrics survey. I want them to see the next question here, not again the question that mentions "click HERE to go to the website". Which would be very confusing).

I have made the following code (based on suggestions I found online), which oddly enough seems to work sometimes, but not always. Could anyone help me out? I would greatly appreciate suggestions on how to improve the code so it always works.

JAVASCRIPT CODE:
Qualtrics.SurveyEngine.addOnload(function() {
  $('extLink').on('click', function(name, event) {
    Qualtrics.SurveyEngine.setEmbeddedData('clicked', '1');
jQuery("#NextButton").click();
});

Additionally, I have used the following settings:

  • In the survey flow, I added an embedded data field named 'clicked' which is set to 0.

  • The hyperlink ID is set as 'ExtLink'


When I look at my data, the first part of the code seems to always work. Hence, clicked is always set to 1 upon clicking on the URL. However, the second part is only triggered sometimes, most of the times it isn't. It seems as if the new URL is opened PRIOR to going to the next question. Hence, this part of the code is not run.

Thanks in advance!

You are trying to go to two different addresses (ExtLink and the next page) at the same time. Add target="_blank" to the external link so ExtLink will open in a new tab/window and NextButton will go to the next page in the current tab/window.


Hi Tom,

Thank you for your reply!

Unfortunately, we very much would like to open the URL in the same window. Namely, we collect data with children, and want to make it as easy as possible for them to 'stay on track'. Hence, if the browser has multiple windows open, we are afraid some of them will get flustered.
Furthermore, we have embedded the survey into the website (that opens upon clicking the URL). Hence, the Qualtrics survey will load there. If we use the "_blank" option, the survey will open in two windows simultaneously. This results in an error message (as there are then 2 versions of 1 participant).

As I understood from your comment, Qualtrics reads the "next page" and "URL" both as 'go to a new page'. Would it be possible in any way to write code in Javascript that tells Qualtrics the order we want these commands to be triggered?
For example:

  • If click on URL, then clicked = 1 AND go to URL

  • If clicked = 1 , then wait 2 seconds, and then auto continue to next question


I have looked into the auto continue options Qualtrics offers (with the "timer" question"). However, I want this timer to only start after clicking the URL. Else, I am afraid participants auto continue without ever clicking the URL.

Thank you again for your help! It is much appreciated.




For anyone looking how to do this, I think I figured it out. TomG thank you again for your comment, it helped me understand why my previous solution did not work!

Below is what I did instead.

JAVASCRIPT CODE:
Qualtrics.SurveyEngine.addOnload(function() {
  $('extLink').on('click', function(name, event) {
    Qualtrics.SurveyEngine.setEmbeddedData('clicked', '1');
});

And, above the question that contains the hyperlink, I added a timer question that auto continues after .1 second. I used a display rule for this item that says "if embedded data field 'clicked' = 1".
Hence, the first time participants run into this question, the embedded data field "clicked" is set to 0. The timer is not triggered. When they click on the hyperlink, the javascript code changes this into "clicked = 1". When the survey re-loads again (for me, embedded on another website), it loads the question again and after .1 second auto continues to the next.




Leave a Reply