[英]Unable to retrive value from select options
whenever I try change the value from dropdown, it shud redirect to other URL.. 每当我尝试从下拉列表更改值时,它都会重定向到其他URL。
anyway, i just had little issue.. 无论如何,我只是没有什么问题。
when I try to change the value, iam not getting brand value, its showing me as: 'undefined' 当我尝试更改价值时,我没有获得品牌价值,它向我显示:“未定义”
Any Idea? 任何想法?
<select id="brand" onchange="gotoPage()">
<?php
$brands = dfr_get_brands_list($category);
foreach ($brands as $brand) : ?>
<option><?php echo $brand; ?></option>
<?php endforeach; ?>
</select>
<?php if (@$_GET['brand']) { ?>
<a href="[server.url type='fullpage' query='-brand']"><FONT COLOR="red"><?php echo"[[X] Remove Brand "; ?><?php echo @$_GET['brand']; ?></font></a>
<?php } ?>
<script>
function gotoPage(){
var url = "http://laptopsisland.com/shop/c/laptops/";
var sel = document.getElementById("brand");
var brand = sel.options[sel.selectedIndex].text;
alert(brand);
window.location.href = url + "&brand=" + brand;
}
</script>
I would chance your options to show something like this 我将有机会选择显示类似这样的内容
<option value="<?php echo $brand; ?>"><?php echo $brand; ?></option>
and then get the selected value as Bokonic mentioned 然后获得Bokonic提到的选定值
sel.options[sel.selectedIndex].value
Let me know how that works. 让我知道它是如何工作的。
You don't need to change the generation code. 您无需更改生成代码。
You also don't need to use getElementById. 您也不需要使用getElementById。
<script>
function gotoPage(e) {
var brand = e.options[e.selectedIndex].text;
alert(brand);
}
</script>
<select id="brand" onchange="gotoPage(this)">
<option>aaa</option>
<option>bbb</option>
</select>
Working solution: http://jsfiddle.net/2YzAV/2/ 工作解决方案: http : //jsfiddle.net/2YzAV/2/
Version with values: http://jsfiddle.net/2YzAV/3/ 带有值的版本: http : //jsfiddle.net/2YzAV/3/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.