如何使用DropDown值onClick Button关注动态网址 - 为什么这不起作用?

时间:2017-08-13 19:45:47

标签: javascript

我看到过类似的帖子,但有一个回答使用了ajax和另一个回复。我无法理解为什么这不起作用。感谢任何解释 - 干杯。

<script >
<select name="region" id="region" tags="region">
<?php echo $regionList; ?>
</select>

function getQuote(){
    e = document.getElementById("region");
    region = e.options[e.selectedIndex].value;
    linkTarget = "http://tatgeturlpage.com' + '?region=' + region ";
    return "window.location=" + linkTarget;
}

</script>

<input type="button" onclick="getQuote()" value="Get Quote">

2 个答案:

答案 0 :(得分:0)

您的&#34;地区&#34;变量读取为字符串而不是选定的值。所以改变这一行:

linkTarget = "http://tatgeturlpage.com' + '?region=' + region ";

要:

linkTarget = "http://tatgeturlpage.com?region=" + region;

答案 1 :(得分:0)

您不能在脚本标记内放置一个select语句。浏览器会忽略它们。尝试在脚本的上方或下方移动它们。