Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

drop down list each option to take me to a different link

I am having a drop down list and I want when I select an option and then click go, to take me to an other link (each option takes me to different link)

This is my code but it doesnt seem to play.

<html>
<head>
<title>
Database Project Winter 2012
</title>
<script>
function goToNewPage(dropdownlist)
 {
 var url = dropdownlist.options(dropdownlist.selectedIndex).value;
 if (url != "")
 {
 window.open(url);
 }
 }
</script>
</head>
<body>
<form name="dropdown">
 <select name="list" accesskey="E">
 <option selected>Select...</option>
 <option value="http://www.google.com/">Google</option>
 <option value="http://www.search.com/">Search.com</option>
 <option value="http://www.dogpile.com/">Dogpile</option>
 <select>
 <input type=button value="Go" onclick="goToNewPage(document.dropdown.list)">
</form>
</body>
</html>

What to change?

like image 464
qwerty_gr Avatar asked Jan 20 '26 22:01

qwerty_gr


1 Answers

Have you considered using a simpler javascript function?

function goToNewPage() {
    if(document.getElementById('target').value){
        window.location.href = document.getElementById('target').value;
    }
}

And adding an ID to the Select element?

<select name="list" id="target">
like image 75
clops Avatar answered Jan 23 '26 20:01

clops