Remove empty input values from URL when submitting an HTML form

For a client I had to build a result page with filters. Visitors could filter the results based on five properties. I wanted to make the result reachable by URL so I choose for the GET method. This way, a link could look like:

The problem I had was that even when some filters were left empty they would still show up.

Luckily it’s possibile with javascript to prevent empty input values from showing up in the URL. There are some hacky methods (changing the element names, or flagging them as disabled), but FormData is the way to go.

Check out this answer on Stack Overflow for a working example: