Saving Survey Results and Advancing

When your Web View step is complete, you will need to save the result (if applicable) and advance to the next step.

Saving a Result

To save a result, use the Complete a Web View Step method of the MyDataHelps.js SDK:

MyDataHelps.completeStep(answer);

Answers from Web View steps are always saved as strings. Numbers, booleans, and complex objects are run through JSON.stringify() prior to being saved.

You can also call completeStep without specifying an answer, for steps that do not capture a response. The system will save an empty string as the survey answer in that case.

Advancing to the Next Step

Calling completeStep automatically continues to the next survey step, or finishes the survey if there are no further steps.

Normal navigation/branching rules can be set within MyDataHelps Designer, allowing you to skip a Web View step or advance to specific steps based on previous results.

Example

In this example, there is a single text box with an ID of “answer” where the user inputs their answer, and a “Continue” button that saves the answer and advances to the next step.

The script code gets the answer from the text box and then submits it as the step’s answer result.

Completing a Web View Step
<input id="answer" type="text" placeholder="Test" />
<button onclick="postAnswer()">Continue</button>
<script>
function postAnswer() {
  var answerInput = document.getElementById("answer");
  var answer = answerInput.value;
  MyDataHelps.completeStep(answer);
}
</script>
<input id="answer" type="text" placeholder="Test" /> <button onclick="postAnswer()">Continue</button> <script> function postAnswer() { var answerInput = document.getElementById("answer"); var answer = answerInput.value; MyDataHelps.completeStep(answer); } </script>

Populating Custom Fields and Demographics

You can store the answer from a Web View step into a custom field or demographic field using MyDataHelps Designer, just as you can for any other step type. See Populating Participant Fields.