I have a simple select option box, the contents of which are generated from a PHP script. 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
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.
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/
尝试使用-
<select name="listToGo" onchange="redirect(this.value);">
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.