下拉菜单链接

时间:2015-01-11 20:41:27

标签: javascript php html encoding

我正在尝试根据所选的选项创建一个打开页面的菜单。

我的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

从我可以告诉它的编码错误,但我无法弄清楚该怎么办,链接也不是很正确

任何帮助表示感谢。

1 个答案:

答案 0 :(得分:0)

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