auto-advance | XM Community
Skip to main content
How can I make my survey auto-advance using JavaScript so that...



after a person selects one answer for each statement in a matrix question (single answer allowed for each statement), it auto-advances to the next page?



Thanks.



--David
Try this



!
- You just have to check the length of the matrix rows and if it matches with the selected choice then it will auto-submit the page.

- The above code will work if you have a single matrix question on a page. if you've multiple questions on a page then we would need to modify the script based on page setup.
Thanks. That is a very helpful direction.



There is a problem here though. If the respondent clicks on an answer for a given statement, and then changes their mind and clicks on another answer for that statement, that "extra" click counts toward the total number of clicks required before auto-forward is invoked.



So in this situation the respondent could be forwarded automatically before they provided an answer to the last statement in the matrix (or more than just the last question if they change their mind a lot on the earlier statements).



any ideas on how to deal with this?



--David
Hi David,



Good point, however, the code is not only checking for the click but it also checks whether the "radio button" for each statement is selected or not.



I did try testing the scenario which you outline above and the code is working fine.



I hope you have a radio button matrix question, correct?
Interesting. I did some testing, and only run into the problem in the following scenario:



I click an answer for statement 1 and statement 2.



Then for the third statement, I click one answer, change my mind and click another answer. I am automatically skipped to the next page.



What is strange is that this behavior only happens with multiple clicks on the third statement, in combination with answers to statement 1 and statement 2.



Here is my Java code:



Qualtrics.SurveyEngine.addOnload(function()

{





jQuery("td").click(function(){



if(jQuery(".ChoiceRow").length == (jQuery(".q-checked").length + 1))

{

jQuery("#NextButton").click()

}



});





});



Qualtrics.SurveyEngine.addOnReady(function()

{

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



});



Qualtrics.SurveyEngine.addOnUnload(function()

{

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



});





Here is my question:



!



Thanks.



--David
I've done this, but not exactly the same way. Anyway, when I did it I found that I had to put the if/click next inside a setTimeout with a delay of zero (which means wait until the js stack is clear). You may be running into a similar type of timing issue (e.g., your q-checked length may be calculated before the class is removed from the originally checked input element).
Thanks @TomG.



@DavidS ... you can try this

!
Very cool. Thanks. I don't find any problems in my tests, even if I change my answers or do the last statement first.



The only concern is that there does seem to be a slight delay as the code is processed, which may to some extent defeat the purpose of auto-forward (though of course at least R does not have to click the Next button).



Thanks again.
@DavidS,



I don't know how much @Mohammedali_Rajapakar_Ugam tested it, but 500 milliseconds seems pretty conservative. You can try reducing that number to minimize the delay. Just don't reduce below the point where it becomes unreliable. As I mentioned earlier, I did it a bit differently, but was able to set the delay to 0.
Thanks. I reduced the delay to 25, and it seems to work fine.
There may be a couple of other potential problems.



One is the kind of matrix question that ends with an "Other -- specify" and asks for text entry with that response. When the respondent clicks on "Other -- specify" they will not have a chance to enter a verbatim response since the question will be forwarded to the next page automatically.



The other issue I am less sure about. It seems that if an "In Page" display logic is used for the next question, there is a conflict between it and the Java script to auto-forward on the current question. Here is a message that I have received several times in this situation.



!





I will let you know if this happens consistently. So far it seems to be a consistent behavior.
The problem that leads to "we are unable to connect to our servers" is not related to the matrix question auto-forward (at least as far as I know). Sorry about that.



The cause of the problem appears to be the use of "In page" display logic and this code for auto-forwarding a multiple choice, single answer question:



var that = this;

this.questionclick = function(event,element){

if (element.type == 'radio') {

that.clickNextButton();

}

}

Leave a Reply