Implement External Form Navigation
SurveyJS ships with multiple navigation features that you can add to your forms: navigation buttons, a table of contents, and various types of progress indicators. You can also implement custom navigation elements that extend the built-in functionality or completely replace it. This demo shows how to implement external form navigation controls—a page selector, navigation buttons, and a progress indicator—and use them in conjunction with built-in form navigation features.
Configure a Page Selector
A page selector is a UI element that displays a list of survey pages and enables users to jump to a selected page. Usually, a page selector is a drop-down menu. If your survey contains a few pages only, a page selector can be a set of buttons with page numbers.
This example demonstrates a drop-down page selector built upon a standard
<select> HTML element. To fill
<select> options, iterate over
visiblePages array and create an
<option> element for each array item. Within the
onchange event handler, assign the selected value to
currentPageNo property. Note that this property starts to enumerate survey pages with 0.
Implement Navigation Buttons
Built-in survey navigation buttons include Start, Next Page, Previous Page, Preview, and Complete. Depending on your use case, you may need to implement all the buttons or only a part of them. This demo implements the Next Page, Previous Page, and Complete buttons.
<button> elements to your page. To navigate between survey pages, call
prevPage() methods or change the
currentPageNo property value within
onclick event handler. To end the survey, call the
Navigation button visibility may depend on the current page. For example, the Previous Page button should not be visible on the first survey page, or the Complete button should appear only when a user has reached the last page. To control button visibility, use
isLastPage properties or compare the
currentPageNo property value with the length of the
If you implement custom navigation buttons, you may want to hide the built-in buttons to avoid functionality duplication. To do this, disable the
showNavigationButtons property. This demo, however, keeps the built-in buttons visible to show how they can work alongside custom buttons.
Add a Progress Indicator
A progress indicator help users understand how far along the survey they have advanced. Progress indicators can show the number of completed survey pages, answered questions, or other progress information. In this demo, a progress indicator displays the current page number and the total number of survey pages. Use
currentPageNo property and the length of the
visiblePages array to implement this progress indicator. Note that
currentPageNo starts to enumerate survey pages with 0, therefore, you need to add 1 to its value to get the actual current page number.
Handle Navigation Events
A survey raises the following events that may be useful when you implement an external navigation system:
Raised when the survey starts.
Raised after the current page is switched.
Raised after the survey is completed.