This example demonstrates how to use query parameters to save and retrieve user input values during a session. The current search values are saved as query parameters in the URL. When a visitor refreshes or navigates back to the site page, their previous search criteria are automatically populated in the user input fields. The site uses a collection, whose data is filtered by the search criteria and then displayed in a repeater.
The code in this file initializes the page elements, listens for events, retrieves the latest user input values, and filters the collection data to display.
In this file, we:
Define variables to keep track of the user input values.
Define event handlers for the following actions:
When the text input element receives input.
When the dropdown element value changes.
Query all the continents from the Continents collection and set the options for the dropdown element.
Retrieve the last user input values from the URL query parameters, if any, and prepopulate the text input and dropdown elements with those values or default options.
Filter the Articles collection and display the content matching the search criteria in the repeater, or show an error message if no results are found.
Update the URL query parameters to reflect the latest user input values after displaying the filtered results.
Join the Wix Studio community on Discord, where experienced developers and fellow creators come together to share tips, troubleshoot issues, and collaborate.
Building a coded solution on your own can be challenging. Let an experienced Wix developer build it for you, so you can keep working on your site or business.
Visit the Wix Marketplace to find a trusted developer.