简体   繁体   English

下拉菜单链接

[英]Dropdown menu to link

Im trying to create a menu that open a page based on the option selected. 我试图创建一个菜单,该菜单基于所选选项打开页面。

my js 我的js

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

} }

my form 我的表格

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

however the page opens as 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?list=http%3A%2F%2Fwww.xxxx.co.uk%2Fcontent.php%3Fid%3Dguide%26sub%3Ddog%26breed打开%3D2

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

from what i can tell its an encoding error but i cannot figure out what to do about it, also the link isnt quite correct 从我可以告诉它的编码错误,但我不能弄清楚该怎么办,而且链接不是很正确

any help appreciated. 任何帮助表示赞赏。

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>";
<?
   }
?>

This avoids encoding issues. 这样可以避免编码问题。 You just build the uri in the goToNewPage function. 您只需在goToNewPage函数中构建uri。 Pass the breed id via the select. 通过选择传递品种id

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM