Documentation Docs
Documentation Docs

Continue an Incomplete Survey

Respondents may not complete your survey in a single session. In this case, you can restore their answers from the previous session next time they get to the survey. Incomplete results can be loaded from your database or the browser's localStorage.

To save incomplete results, implement a function that sends them to your server or saves them in the localStorage. Call this function within SurveyModel's onValueChanged and onCurrentPageChanged event handlers to save survey results when users change a question value or switch between pages. If you use the localStorage, you also need to delete survey results from it when the survey is completed. Handle the onComplete event for this purpose.

import { Model } from "survey-core";

const surveyJson = { ... };
const survey = new Model(surveyJson);

const storageItemKey = "my-survey";

function saveSurveyData (survey) {
  const data = survey.data;
  data.pageNo = survey.currentPageNo;
  window.localStorage.setItem(storageItemKey, JSON.stringify(data));
}

// Save survey results to the local storage
survey.onValueChanged.add(saveSurveyData);
survey.onCurrentPageChanged.add(saveSurveyData);

// Restore survey results
const prevData = window.localStorage.getItem(storageItemKey) || null;
if (prevData) {
  const data = JSON.parse(prevData);
  survey.data = data;
  if (data.pageNo) {
    survey.currentPageNo = data.pageNo;
  }
}

// Empty the local storage after the survey is completed
survey.onComplete.add(() => {
  window.localStorage.setItem(storageItemKey, "");
});

View Demo

See Also

Send feedback to the SurveyJS team

Need help? Visit our support page

Copyright © 2024 Devsoft Baltic OÜ. All rights reserved.

Your cookie settings

We use cookies on our site to make your browsing experience more convenient and personal. In some cases, they are essential to making the site work properly. By clicking "Accept All", you consent to the use of all cookies in accordance with our Terms of Use & Privacy Statement. However, you may visit "Cookie settings" to provide a controlled consent.

Your renewal subscription expires soon.

Since the license is perpetual, you will still have permanent access to the product versions released within the first 12 month of the original purchase date.

If you wish to continue receiving technical support from our Help Desk specialists and maintain access to the latest product updates, make sure to renew your subscription by clicking the "Renew" button below.

Your renewal subscription has expired.

Since the license is perpetual, you will still have permanent access to the product versions released within the first 12 month of the original purchase date.

If you wish to continue receiving technical support from our Help Desk specialists and maintain access to the latest product updates, make sure to renew your subscription by clicking the "Renew" button below.