2

I am trying to redirect my static html page to another when user i select any particular option from input type select.

let's say. When user select USA from country dropdown.. Redirect to Google. Is their any simple jquery or javascript to do this.

Thanks in advance :)

Munish Kumar
  • 45
  • 1
  • 5

7 Answers7

4

You could use dataset elements

$("#select").change(function() {
  var option = $(this).find('option:selected');
  window.location.href = option.data("url");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select id="select">
  <option data-url="http://www.google.com">USA</option>
  <option data-url="http://www.twitter.com">Canada</option>
</select>
tomiy
  • 146
  • 6
1

Please do a search be sure you find your question quickly. I answered this question before in this topic:

how change the link form action a accordance with the `<option>`?

that's what you want.

Community
  • 1
  • 1
Pedram
  • 15,766
  • 10
  • 44
  • 73
0
<select>
 <option onclick="redirect()">USA<option>
</select>

 <script>

  function redirect(){
    window.location.href = 'http://www.google.com';
  }

  </script>
Sukhwinder Sodhi
  • 455
  • 1
  • 4
  • 18
0

Try something like this

$("#idselect").change(function(){
   var choice = $(this).val();
   switch(choice)
   {
       case "USA":
       window.location.url="www.google.com";
       break;
       case "ENG":
       window.location.url="www.google.com";
       break;
       default : 
       //Default action
       break;
   }
});
Alexis
  • 5,681
  • 1
  • 27
  • 44
0

In jquery you can do the following

('#dropdown').change(function(){
window.location.href = "your new url";
});
REDEVI_
  • 684
  • 8
  • 18
0

Checkout the complete HTML, Copy and save it in HTML extension.

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<script type="text/javascript">
 $( document ).ready(function() {
   $('select[name=country]').on("change", function(e){

      if($(this).val() == 'USA'){
          alert($(this).val());
          window.location.assign("http://www.w3schools.com")
      }
      //window.location.url="www.google.com";
   });
});
</script>

</head>
<body>

<Select name="country">
   <option value="India">India</option>
   <option value="USA">USA</option>
</Select>

</body>
</html>

Hope this helps.

Vinoth Krishnan
  • 2,925
  • 6
  • 29
  • 34
0

Use below code:-

<select onchange="this.options[this.selectedIndex].value && (window.location = this.options[this.selectedIndex].value);">
    <option value="">Select...</option>
    <option value="http://google.com">USA</option>
    <option value="http://yahoo.com">Canada</option>
</select>

Original Link:-

Community
  • 1
  • 1
Ravi Hirani
  • 6,511
  • 1
  • 27
  • 42