Simple onChange Redirect JavaScript select tag

Are you looking for a very simple JavaScript that can redirect to an URL onChange of the Dropdown box?

Here is the code which is ready to use on any of your project.

1.  JavaScript:


<script type="text/javascript">
function gotopage(selval){
var value = selval.options[selval.selectedIndex].value;
window.location.href=value;
}
</script>

2. Here is the HTML Part:


<select onchange="gotopage(this)">
<option value="">Select</option>
<option value="https://www.google.com">Google</option>
<option value="https://www.yahoo.com">Yahoo</option>
<option value="https://www.msn.com">MSN</option>
</select>

For your Convenience here is the Entire Javascript Redirect Example:


<html>
<head>
<script type="text/javascript">
function gotopage(selval){
var value = selval.options[selval.selectedIndex].value;
window.location.href=value;
}
</script>
</head>
<body>
<h3>Onchange Redirect Script</h3>
<select onchange="gotopage(this)">
<option value="">Select</option>
<option value="https://www.google.com">Google</option>
<option value="https://www.yahoo.com">Yahoo</option>
<option value="https://www.msn.com">MSN</option>
</select>
</body>
</html>

Leave a Reply

Theme: Overlay by Kaira
Agurchand