Reputation: 1561
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.
Upvotes: 0
Views: 63
Reputation: 42166
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/
Upvotes: 1
Reputation: 4858
Try using this -
<select name="listToGo" onchange="redirect(this.value);">
Upvotes: 0