要链接的下拉菜单


Dropdown menu to link

我试图创建一个菜单,根据所选选项打开页面。

我的 JS

<script type="text/javascript" language="JavaScript">
function goToNewPage() {
if(document.getElementById('target').value){
    window.location.href = document.getElementById('target').value;
}

}

我的表格

<form class="smart-green" name="dropdown">
<select name="list" id="target">
<?
include_once ("xxxx");
$sql = mysql_query("xxxx");
while($row = mysql_fetch_assoc($sql))
{?>
<option value="http://www.xxxx.co.uk/content.php?id=guide&sub=dog&breed=<? echo $row['id'];?>"><? echo $row['breed'];?></option>";
<?
}
?>
</select><br /><br />
<input type="submit" class="button" onClick="goToNewPage(document.dropdown.list)" value="Find Breed">
</form>

但是页面打开方式为 http://www.xxxx.co.uk/content.php?list=http%3A%2F%2Fwww.xxxx.co.uk%2Fcontent.php%3Fid%3Dguide%26sub%3Ddog%26breed%3D2

而不是http://www.xxxx.co.uk/content.php?id=guide&sub=dog&breed=2

据我所知,这是一个编码错误,但我无法弄清楚该怎么做,而且链接也不太正确

任何帮助表示赞赏。

function goToNewPage() {
  if(document.getElementById('target').value){
     window.location.href = "http://www.xxxx.co.uk/content.php?id=guide&sub=dog&breed="+document.getElementById('target').value;
  }
<?
   include_once ("xxxx");
   $sql = mysql_query("xxxx");
   while($row = mysql_fetch_assoc($sql))
   {?>
       <option value="echo $row['id']; ?>"><? echo $row['breed'];?></option>";
<?
   }
?>

这样可以避免编码问题。您只需在 goToNewPage 函数中构建 uri。通过选择传递品种id