Saving Survey Results and Advancing

Your Web View step can return a single answer, which will be saved in the survey results. This is done with the postMessage method:

window.webkit.messageHandlers.ResearchKit.postMessage(answer);

Advancing to the Next Step

Posting an answer also continues to the next survey step.

Normal navigation/branching rules apply, allowing you to skip a web view step or advance to specific steps based on previous results.

Populating Custom Fields and Demographics

You can store the answer from a Web View step into a custom field or demographic field just as you can for any other step type. See Setting Custom Fields From Survey Answers or Setting Demographic Fields From Survey Answers .

Storing Complex Data

Answers from Web View steps are always saved in string format. However, if you have a complex answer you can use JSON.stringify to save a JSON object as a string.

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.

<input id="Answer" type="text" placeholder="Test" />
<button onclick="postAnswer()">Continue</button>
<script>
function postAnswer() {
  var answerInput = document.getElementById("Answer");
  var answer = answerInput.value;
  window.webkit.messageHandlers.ResearchKit.postMessage(answer);
}
</script>