0

i have form two dropdown as:

<form id="redirect">
  <select id="location">
    <option value="bus">Bus</option>
    <option value="station">Station</option>
    <option value="office">Office</option>
  </select>

  <select id="goto">
    <option value="home">Home</option>
    <option value="city">Cty</option>
  </select>  

  <input type="submit" value="submit"></input>
</form>

How to use Javascript for submit redirect select dropdown as

if #location = Bus && #goto = Home => Click submit redirect =>>google.com

if #location = Bus && #goto = Cty => Click submit redirect =>>facebook.com

match for other #location as

if #location = Station && #goto = Home => Click submit redirect =>>url1.com

if #location = Cty && #goto = Cty => Click submit redirect =>>url2.com

Thank you so much!

DinhCode
  • 110
  • 10

1 Answers1

0

Here's how you'd do it:

var form = document.getElementById("redirect");
form.onsubmit = function() {
    var location = document.getElementById("location").value;
    var goto = document.getElementById("goto").value;
    if (location == "Bus") {
        if (goto == "Home") {
            window.location.href = "https://google.com";
        }
        else {
            window.location.href = "https://facebook";
        }
    } else {
        if (goto == "Home") {
            window.location = "a url";
        } 
        else {
            window.location.href = "another url";
        }
    }
}     

Change those URLs as you'd like.

Jack Bashford
  • 43,180
  • 11
  • 50
  • 79