How to stop the default behavior of next button click? | XM Community
Solved

How to stop the default behavior of next button click?

  • 14 June 2018
  • 8 replies
  • 291 views

Badge +1
I would like to know if there is any JS API we can use, when the next button is clicked, to stop(or delay) the page submit to execute some of our custom functionality.
icon

Best answer by TomG 22 June 2018, 15:24

View original

8 replies

Userlevel 7
Badge +6
What specifically are you trying to do? Would the .addonUnload section not accomplish this?

!
Badge +1
Below is the code snippet I am trying to do:
Qualtrics.SurveyEngine.addOnUnload(function(type)
{
var clientId = 'ClientId';
var userId = 'UserId';
var password = 'password';
var surveyId = "${e://Field/SurveyID}";
var responseId = "${e://Field/ResponseID}";
var pageId = "P1";
var matrixData = getMatrixData();
CollectData(clientId, userId, password, surveyId, responseId,pageId,matrixData);

function getEngagedResult(jsonData) {
if (jsonData.Success) {
alert(jsonData.Success);
//The page submit should wait till this block is reached
} else {
// check jsonData.ErrorMsg
}
}
});
Userlevel 7
Badge +27
Change addOnUnload to addOnPageSubmit. The question data on the page will already be gone by the time addOnUnload executes.
Badge +1
I tried doing that but next page loads before i receive response from the third party API I am calling. I need to stop navigating to next page until i receive the response(success) from the other api.
Userlevel 7
Badge +27
You could put next question in a new block and call the third party API with with web service from the survey flow.
Badge +1
Not sure on the web service from survey flow, but for now, I am trying to use an empty page/block(a descriptive question asking survey responses to hang on), store response from previous page/block in session, hide next button, submit them in page load and click next button when response is received. If that does not work out, I will go with web service call. Thanks a lot, TomG.
Badge +1
Hi TomG, my requirement is to add few hidden variables in the page/block with an open ended question, when the next button is clicked, submit the values of open ended text area and the hidden variables to third party api, set the response values from third party api into embedded data. Can you elaborate more on the suggestion you were providing with web service?
Userlevel 7
Badge +27
A web service call is perfectly suited to what you are trying to do. You can add the hidden variables directly to the web service as parameters, then pipe the question text value into the web service as another parameter. As long as the third party api returns json or xml, the returned data will populate embedded variables.

Here is information on adding a web service to your survey flow.

Leave a Reply