Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
World desk3 min

How to Update the URL After a Form Is Submitted

Use GET for bookmarkable searches and filters, POST then redirect for changes to server data, or the History API when a JavaScript app updates results without navigating.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For a search, sort, or filter form, use method="get" and give each control its own name. The browser then puts the submitted values in the URL query string. For a form that changes data, use POST and redirect to a result URL; for a JavaScript app that stays on the same page, update the URL with URLSearchParams and the History API.

Use a GET form for searches, sorting, and filters

GET is the simplest way to reflect submitted values in the URL when the form requests or filters a representation rather than changing server data. Each field needs a name; that name becomes the query parameter. See MDN’s HTML form documentation and its GET method reference.

As an Amazon Associate I earn from qualifying purchases.

<form action="/finance/markets/" method="get">
  <label for="sortname">Sort by</label>
  <select id="sortname" name="sortname">
    <option value="date">Date</option>
    <option value="title">Title</option>
  </select>

  <label for="sortdir">Direction</label>
  <select id="sortdir" name="sortdir">
    <option value="asc">Ascending</option>
    <option value="desc">Descending</option>
  </select>

  <button type="submit">Apply</button>
</form>

If the user selects Title and Descending, submitting navigates to a URL shaped like /finance/markets/?sortname=title&sortdir=desc. The exact path comes from action, and the query values come from the selected options.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Keep separate values in separate named controls. Putting sortdir=desc inside the sortname option’s value does not create a second parameter; it remains part of one value and is encoded accordingly. HTML forms default to GET when no method is specified, but writing method="get" makes the intended behavior explicit.

Use POST and redirect when the form changes data

For actions such as creating an account or saving a record, submit with POST and process the request on the server. If the user should finish on a clean result page, respond with a redirect to a URL such as /results?sortname=title&sortdir=desc. Build the query using the server language’s URL-encoding tools and include only values the server has accepted and validated.

A 303 See Other is useful for this POST-then-redirect pattern: the browser follows the redirect with a GET request to the destination. Consult MDN’s 303 status documentation. Do not put passwords or similarly sensitive values in query parameters; URLs can be visible in the address bar and exposed through systems that handle URLs. POST keeps submitted form data in the request body, though it does not by itself make a submission secure.

Rank #2
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Update the URL in a JavaScript app

If JavaScript handles the form and displays results without a full-page navigation, construct the query with URLSearchParams rather than concatenating raw strings. Then use the History API to add or replace the current history entry.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
const params = new URLSearchParams(new FormData(form));
const url = new URL(window.location.href);

for (const [key, value] of params) {
  url.searchParams.set(key, value);
}

// Update or fetch the app's results separately.
history.pushState(
  { sort: url.searchParams.get("sortname") },
  "",
  url
);

Use pushState() when the change should create a Back-button step. Use replaceState() when it should update the current entry instead. Both require a same-origin URL. These calls change the address bar and browser history; they do not fetch the URL or render the corresponding results. Your app must update its UI separately and restore the right state when the user navigates Back or Forward. See MDN’s pushState reference and URLSearchParams documentation.

Rank #4
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers

Choose the right approach

Form purpose Approach Result
Search, sort, or filter results that should be shareable or bookmarkable GET form with named fields The browser submits the field values as query parameters.
Save data or perform another state-changing action POST, then redirect to a result URL The server processes the submission, then the browser visits a clean destination with GET.
JavaScript app updates results without navigating URLSearchParams with pushState() or replaceState() The app can synchronize its URL, history, and interface state.
Submission contains a password or another sensitive value POST; keep the value out of the URL The value is submitted in the request body rather than a query string.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.