[英]How do I follow dynamic url with DropDown Value onClick Button - why wont this work?
I have seen a post similar to this but one answer used ajax and the other form/post. 我看到过类似的帖子,但是一个答案使用了ajax,而另一个答案使用了表单/帖子。 I can't figure why this won't work.
我不知道为什么这行不通。 Grateful for any explanation - Cheers.
感谢您的解释-干杯。
<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">
Your "region" variable is read as a string rather than the selected value. 您的“区域”变量将被读取为字符串,而不是所选值。 So Change this line:
因此,更改此行:
linkTarget = "http://tatgeturlpage.com' + '?region=' + region ";
To: 至:
linkTarget = "http://tatgeturlpage.com?region=" + region;
You can't put a select statement inside of script tags. 您不能将select语句放在脚本标签内。 The browser will ignore them.
浏览器将忽略它们。 Try moving them either above or below the script.
尝试将它们移动到脚本上方或下方。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.