简体   繁体   English

未触发onchange事件

[英]onchange event not being triggered

I have a simple select option box, the contents of which are generated from a PHP script. 我有一个简单的选择选项框,其内容是从PHP脚本生成的。 I looks like this 我看起来像这样

<form action="php/reloadNewList.php" method="POST">
    <select name="listToGo" onchange="redirect(this.form.value)">
    <?php 
    include('php/getMyList.php');
    getList(); 
    ?>
    </select>
</form>

The list generated looks fine 生成的列表看起来不错

<option value="1">Hello</option>
<option value="12">Smelly</option>
etc

My JS script is simple enough as well 我的JS脚本也很简单

function redirect(value)
{
    var x=value.selectedIndex;
    alert("listToGo="+x + "\nValue = "+value);
    document.cookie = "ListCookie="+x;
    window.location.reload();
}

The problem I'm getting is that the onchange is not responding to the change on the drop down list. 我遇到的问题是onchange没有响应下拉列表上的更改。

Try to change: 尝试更改:

<select name="listToGo" onchange="redirect(this)">

And: 和:

function redirect(slct)
{
    console.log(slct)
    var x=slct.selectedIndex;
    var value = slct.value;
    alert("listToGo="+x + "\nValue = "+value);
    document.cookie = "ListCookie="+x;
    window.location.reload();
}

JSFiddle: http://jsfiddle.net/cherniv/YyUwR/1/ JSFiddle: http : //jsfiddle.net/cherniv/YyUwR/1/

尝试使用-

<select name="listToGo" onchange="redirect(this.value);">

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

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