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

How to stop the default behavior of next button click?


Forum|alt.badge.img+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.

Best answer by TomG

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.
View original

8 replies

Akdashboard
Level 4 ●●●●
Forum|alt.badge.img+6
  • Level 4 ●●●●
  • 488 replies
  • June 14, 2018
What specifically are you trying to do? Would the .addonUnload section not accomplish this? !

Forum|alt.badge.img+1
  • Author
  • 6 replies
  • June 14, 2018
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 } } });

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 5938 replies
  • June 14, 2018
Change addOnUnload to addOnPageSubmit. The question data on the page will already be gone by the time addOnUnload executes.

Forum|alt.badge.img+1
  • Author
  • 6 replies
  • June 15, 2018
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.

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 5938 replies
  • June 15, 2018
You could put next question in a new block and call the third party API with with web service from the survey flow.

Forum|alt.badge.img+1
  • Author
  • 6 replies
  • June 15, 2018
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.

Forum|alt.badge.img+1
  • Author
  • 6 replies
  • June 22, 2018
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?

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 5938 replies
  • Answer
  • June 22, 2018
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