HTML:
<select name="myList" id="ddlMyList"> <option value="http://www.google.com">Google</option> <option value="http://www.yahoo.com">Yahoo</option> <option value="http://www.ask.com">Ask</option> </select> <input type="button" value="Go To Site!" onclick="NavigateToSite()" />
JavaScript:
function NavigateToSite(){ var ddl = document.getElementById("ddlMyList"); var selectedVal = ddl.options[ddl.selectedIndex].value; window.location = selectedVal; }
You can also open the site in a new window by following these steps:
function NavigateToSite(){ var ddl = document.getElementById("ddlMyList"); var selectedVal = ddl.options[ddl.selectedIndex].value; window.open(selectedVal) }
As a side note, your parameter tags are not formatted properly. You should never use the <... / "> label if the tag contains content.
source share