Search code examples
javascriptforms

Redirect page to different URL using select dropdown and submit button


I want to create a form that redirect the user to a different URL when they select an option from the select dropdown and click the submit button. Here is the markup for my form below:

<form>
  <select>
    <option selected="">- Select -</option>
    <option value="https://google.com">One</option>
    <option value="https://gmail.com">Two</option>
    <option value="https://yahoo.com">Three</option>
  </select>
  <input type="submit" value="Submit">
</form>

Solution

  •   <select id="select_location">
        <option selected="">- Select -</option>
        <option value="https://google.com">One</option>
        <option value="https://gmail.com">Two</option>
        <option value="https://yahoo.com">Three</option>
      </select>
      <input type="button" value="Submit" onclick="window.location=document.getElementById('select_location').value;">