HTML/JavaScript Dropdown List Redirect

Recently on a forum the question was asked how to redirect using a dropdown and not using any server side scripting - the answer turns out to be pretty simple

All that is needded is a simple Javascript function that takes in a drop-down list as an input, takes the value of the selected option and run it through a location.href.  Here is the JavaScript:

function Navigate(drop_down_list) {
   var number = drop_down_list.selectedIndex;
   location.href = drop_down_list.options[number].value; }

Then all you need to do is add a dropdown list setting the values to the urls you want to navigate to, and the onclick event set to Navigate(name_of_dropdown) and you are all ready to go. Here is a quick example:



Comments are closed