Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk3 min

How to Redirect to a URL When a Dropdown Option Is Selected

A concise JavaScript pattern for navigating to a selected URL, plus guidance on labels, user expectations, links, and server-side redirects.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To send a visitor to a page after they choose an option, read the HTML <select> element’s selected value in a JavaScript change handler, then navigate with window.location.assign(). Use an empty prompt option so the initial selection is not treated as a destination.

Redirect when a visitor selects an option

In each <option>, put the destination URL in value and the human-readable choice between the tags. The select element’s JavaScript value property gives you the value of the selected option, as described in MDN’s documentation for the HTML select element.

As an Amazon Associate I earn from qualifying purchases.

<label for="destination">Choose a destination</label>
<select id="destination">
  <option value="">Choose a page</option>
  <option value="/about">About</option>
  <option value="/contact">Contact</option>
</select>

<script>
  const destination = document.querySelector("#destination");

  destination.addEventListener("change", () => {
    if (destination.value) {
      window.location.assign(destination.value);
    }
  });
</script>

The listener runs when the selection changes. The empty value on “Choose a page” makes the if check ignore the prompt rather than navigating to an empty destination. window.location.assign() performs client-side navigation; MDN documents it as a JavaScript redirection method in its guide to HTTP redirections.

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

This example assumes the option values are authored and controlled by the site. If destinations can be influenced by untrusted input, validate them or restrict them to an allowlist of permitted URLs.

Choose the right interaction

Approach Use it when Trade-off
Select with an automatic JavaScript redirect The list is compact and it is clear to users that choosing an option will navigate immediately. Requires JavaScript, and the selection itself changes the page.
Select with a separate Go button Visitors should be able to choose and review an option before leaving. Adds an action step; make the button’s purpose clear.
Ordinary links The choices are destinations users may want to open, copy, bookmark, or activate individually. A long list can take more space than a select. An anchor with a real href represents a hyperlink to a URL; see MDN’s anchor-element guidance.
Server-side HTTP redirect The server should send a requested URL to a canonical or replacement location consistently. This is a server-configured rule, not a per-user menu choice.

For a separate action, keep the same labeled select and read its value from the button’s click handler instead of navigating in the change handler. That lets the visitor confirm the choice before the page changes.

If the choices are simply page links, use real links rather than a fake anchor such as href="#" or javascript:void(0). MDN notes that placeholder anchors can behave unexpectedly when copied, dragged, opened in a new tab, bookmarked, or when JavaScript is unavailable.

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

Make the dropdown understandable and predictable

  • Associate a visible <label> with the select using matching for and id values, and give each option meaningful text. MDN describes a select as typically being associated with a label.
  • Tell visitors when choosing an option will take them to another page. A selection change does not inherently need to change context: W3C WAI’s SCR19 technique demonstrates using a select’s change event to update another element without navigating. W3C presents techniques as examples, not mandatory implementations.
  • Do not navigate just because the page loaded with a default selection. Trigger navigation from the user’s change or button action.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

When to use a server redirect instead

A dropdown is a user interface for choosing among destinations. A redirect rule is a server response that sends a requested URL elsewhere. For a permanent move or a temporary redirect, configure the corresponding HTTP response on the server when possible. MDN recommends HTTP redirects where they fit because the server handles them before sending the page; unnecessary internal redirect hops add performance cost. Its redirect guide also explains that permanent and temporary status codes differ in how they communicate the move and handle request methods.

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

The JavaScript pattern above only works when the visitor’s browser executes JavaScript. It is not a substitute for a server redirect when the destination rule must be enforced by the server.

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

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
Crashes, No Sound, or Screen Glitches?Free driver scan
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.