top of page
Query Parameters

Query Parameters

Add and remove query parameters from a URL

Intermediate.png

Intermediate

8K

Published:

August 10, 2020

Girl Enjoying her Drink

by

Anchor 1
Hire a Developer

Example Description

In this example, we demonstrate how to add, remove, and get query parameters from the page URL displayed in a browser. Query params are optional key-value pairs added to a URL following a question mark that allow websites to store data about a particular page. Query params are used for filtering and sorting page content, validating user tokens, pagination, improving SEO, and receiving form data.

Example Code

Tab 1

.

Tab 2

.

Tab 3

.

This code solution can be complicated.

How We Built It

 

Page Elements

We added a form with 3 sections:

  • Add query params:

    • 2 text inputs for entering the query param key and value

    • Add button

    • Text element for displaying messages

  • Remove query params:

    • Text input for entering the query param key to remove

    • Remove button

    • Text element for displaying messages

  • Get query params:

    • Text element for displaying the current query params

    • Get button

 

Code

Our site contains the following code:

  • When the Add button is clicked, do the following:

  1. If the input values are valid, add the query param to the URL displayed in your browser, change the Add button text to “Add another one”, show a success message, and reset validity indicators.

  2. If the input values are not valid, display an error message.

  • When the Remove button is clicked, do the following:

  1. Grab the value of the query param key to remove and reset the input.

  2. If the displayed URL has a query section and the query has a key matching the input value, remove the query param and show a success message.

  3. If there is no query param with the specified key, show an error message.

  • When the Get button is clicked, do the following:

  1. Check if the displayed URL has a query section. If it does, display the queries in the text element. 

  2. Since the queries are part of a JSON object, we use the JSON.stringify() JavaScript function to convert the queries into a string that can be displayed in a text element.

APIs We Used

Non-code example.

Non-code example.

Non-code example.

Non-code example.

Related Articles

Hire a Developer

Velo solutions are powerful tools, but building them on your own can be challenging. Let an experienced Velo development shop build it for you, so you can keep working on your site or business.

Related Examples

Did this help?

Yes

|

No

Thanks for your feedback!

Filter With Multiple Options

Filter With Multiple Options

Filter a repeater with multiple options using the Selection Tags element.

Intermediate.png

Intermediate

Checkbox Dropdown

Checkbox Dropdown

Search a site using multiple filters.

Intermediate.png

Advanced

To-Do List

To-Do List

Let visitors create, filter and update their own customized to-do list.

Intermediate.png

Intermediate

Anchor 2
bottom of page