force response and auto-advance option | XM Community
Skip to main content
Question

force response and auto-advance option

  • 25 June 2023
  • 6 replies
  • 625 views

I need to include in my survey some questions that will auto-advance after a specified amount of time (20 seconds). However, the questions with timer are mandatory, in the sense that I want the participant to provide an answer before moving to the next page within this 20 seconds. However, if the participant has not provided an answer in the 20 second, I want to move on to the next question even without an answer. Currently, this is not possible because with mandatory question, even if the timer has expired, the survey does not advance to the next question, but it restarts the count down so that the participant has all the time she wants to reply. 

Do you have any suggestion on how to do it? Qualtrics support suggested require response but I’m not satisfied as the participant can go on even without answering. Also, I don't want to delay the visibility of the submit button, as participants should be free to advance as soon as they have answered the question.

I thought about a javascript that automatically gives an answer to be able to move on (and keep track of the questions for which the answer was given by the system, to avoid including them in my data analysis), but I don’t know how to code it. 

Any help is more than appreciated, thanks! 

6 replies

Userlevel 5
Badge +14

Hi

 

Here's an example Javascript of how you can implement it in Qualtrics

Qualtrics.SurveyEngine.addOnload(function() {
  var questionId = 'QID1'; // Replace 'QID1' with the actual question ID
  
  var timer = setInterval(function() {
    var answer = jQuery("#" + questionId + " .InputText").val();
    
    if (!answer) {
      clearInterval(timer);
      this.clickNextButton();
    }
  }, 20000); // Specify the time limit in milliseconds (20 seconds in this example)
});
 

With this code, the timer starts when the page loads. If the participant hasn't provided an answer within the specified time limit (20 seconds in this snippet), the JavaScript code will automatically click the "Next" button, advancing to the next question. If an answer is provided within the time limit, the timer will be cleared, and the participant can manually proceed by clicking the "Next" button.

Remember to repeat these steps for each question that requires the auto-advance timer.

Userlevel 7
Badge +27

@VFF_27 - What type of question are you using? Single answer multiple choice?

Badge +2

Thanks! For the questions, I’ve MCQ with 2 real options and 1 that is hidden for the purpose of the code.

 

Actually putting together your and previous answers answers, some help by ChatGPT, I managed to solve the issue with this code (there doesn’t seem to be mistakes but if you see any I’ll be happy to receive your feedback):

 

Qualtrics.SurveyEngine.addOnReady(function() {
    /*Place your JavaScript here to run when the page is fully displayed*/
    var questionId = this.questionId;
    var choiceIdToSelect = 3;
    var timerExpired = false;
    
    // Hide choice 3 initially
    jQuery("#" + questionId + " input[choiceid=" + choiceIdToSelect + "]").closest("li").hide();
    
    // Start the timer for 20 seconds
    setTimeout(function() {
        // Check if the timer has already expired
        if (!timerExpired) {
            // Check if choices 1 or 2 are selected
            var choice1Selected = jQuery("#" + questionId + " input[choiceid=1]").prop("checked");
            var choice2Selected = jQuery("#" + questionId + " input[choiceid=2]").prop("checked");
            
            if (!choice1Selected && !choice2Selected) {
                // Select choice 3 programmatically
                jQuery("#" + questionId + " input[choiceid=" + choiceIdToSelect + "]").prop("checked", true).change();
            }
            
            timerExpired = true;
        }
    }, 20000); // 20 seconds
});

 

Badge +1

I need to include in my survey some questions that will auto-advance after a specified amount of time (20 seconds). However, the questions with timer are mandatory, in the sense that I want the participant to provide an answer before moving to the next page within this 20 seconds. However, if the participant has not provided an answer in the 20 second, I want to move on to the next question even without an answer. Currently, this is not possible because with mandatory question, even if the timer has expired, the survey does not advance to the next question, but it restarts the count down so that the participant has all the time she wants to reply. 

Do you have any suggestion on how to do it? Qualtrics support suggested require response but I’m not satisfied as the participant can go on even without answering. Also, I don't want to delay the visibility of the submit button, as participants should be free to advance as soon as they have answered the question.

I thought about a javascript that automatically gives an answer to be able to move on (and keep track of the questions for which the answer was given by the system, to avoid including them in my data analysis), but I don’t know how to code it. 

Any help is more than appreciated, thanks! 

 

 

Hey I have a similar situation:
 

I have 5 MCQ questions in a block , all separated by a page break. Each question has 3 options.  I want to add  timer  for 45 seconds for each question and auto-advance to the next question when the time is up.  Each question is mandatory (force response) but if they don’t answer the question within 45 seconds, I want them to be moved to the next question. 

I also want the questions to stay in the same block as I am scoring the questions in a block. 
Can you help me with this code.

 

 

Badge +1

Thanks! For the questions, I’ve MCQ with 2 real options and 1 that is hidden for the purpose of the code.

 

Actually putting together your and previous answers answers, some help by ChatGPT, I managed to solve the issue with this code (there doesn’t seem to be mistakes but if you see any I’ll be happy to receive your feedback):

 

Qualtrics.SurveyEngine.addOnReady(function() {
    /*Place your JavaScript here to run when the page is fully displayed*/
    var questionId = this.questionId;
    var choiceIdToSelect = 3;
    var timerExpired = false;
    
    // Hide choice 3 initially
    jQuery("#" + questionId + " input[choiceid=" + choiceIdToSelect + "]").closest("li").hide();
    
    // Start the timer for 20 seconds
    setTimeout(function() {
        // Check if the timer has already expired
        if (!timerExpired) {
            // Check if choices 1 or 2 are selected
            var choice1Selected = jQuery("#" + questionId + " input[choiceid=1]").prop("checked");
            var choice2Selected = jQuery("#" + questionId + " input[choiceid=2]").prop("checked");
            
            if (!choice1Selected && !choice2Selected) {
                // Select choice 3 programmatically
                jQuery("#" + questionId + " input[choiceid=" + choiceIdToSelect + "]").prop("checked", true).change();
            }
            
            timerExpired = true;
        }
    }, 20000); // 20 seconds
});

 

Hi I tried using the code for my question ( 3 options) and was hiding the fourth option. However, the timer stops at 0 seconds (45 sec to 0 sec)  but doe not move to the next question. Can you please help, here is my code:
 

Qualtrics.SurveyEngine.addOnReady(function() {
    /*Place your JavaScript here to run when the page is fully displayed*/
    var questionId = this.questionId;
    var choiceIdToSelect = 4;
    var timerExpired = false;
    
    // Hide choice 4 initially
    jQuery("#" + questionId + " input[choiceid=" + choiceIdToSelect + "]").closest("li").hide();
    
    // Start the timer for 20 seconds
    setTimeout(function() {
        // Check if the timer has already expired
        if (!timerExpired) {
            // Check if choices 1 or 2 are selected
            var choice1Selected = jQuery("#" + questionId + " input[choiceid=1]").prop("checked");
            var choice2Selected = jQuery("#" + questionId + " input[choiceid=2]").prop("checked");
            var choice3Selected = jQuery("#" + questionId + " input[choiceid=3]").prop("checked");

            if (!choice1Selected && !choice2Selected && !choice3Selected) {
                // Select choice 4 programmatically
                jQuery("#" + questionId + " input[choiceid=" + choiceIdToSelect + "]").prop("checked", true).change();
            }
            
            timerExpired = true;
        }
    }, 45000); // 45 seconds
});

Userlevel 3
Badge +13

Hi @supadhyay 

 

you can try it with this

 

Qualtrics.SurveyEngine.addOnReady(function() {

    /*Place your JavaScript here to run when the page is fully displayed*/

    var questionId = this.questionId;

    var choiceIdToSelect = 4;

    var timerExpired = false;

    

    // Hide choice 4 initially

    jQuery("#" + questionId + " input[choiceid=" + choiceIdToSelect + "]").closest("li").hide();

    

    // Start the timer for 45 seconds

    setTimeout(function() {

        // Check if the timer has already expired

        if (!timerExpired) {

            // Check if choices 1, 2, or 3 are selected

            var choice1Selected = jQuery("#" + questionId + " input[choiceid=1]").prop("checked");

            var choice2Selected = jQuery("#" + questionId + " input[choiceid=2]").prop("checked");

            var choice3Selected = jQuery("#" + questionId + " input[choiceid=3]").prop("checked");

            if (!choice1Selected && !choice2Selected && !choice3Selected) {

                // Select choice 4 programmatically

                jQuery("#" + questionId + " input[choiceid=" + choiceIdToSelect + "]").prop("checked", true).change();

            }

            

            // Move to the next question

            Qualtrics.SurveyEngine.setEmbeddedData("TimerExpired", "true");

            jQuery("#NextButton").click();

            

            timerExpired = true;

        }

    }, 45000); // 45 seconds

});

 

Leave a Reply