jimmyh
12-15-2006, 08:39 AM
I have a select element created in javascript and I've set the onchange event to call a function, but for some reason it is not being called in IE6, it works fine in Opera and Firefox.
I've played around with all the script setting in IE but still cant get it to work. If any one could have a quick look and see if they can spot a problem that would be great.
Here is my code.
<html>
<script language='javascript'>
function runThisFunc()
{
alert("HelloWorld");
}
function init()
{
p = document.getElementById("mydiv");
s = document.createElement("SELECT");
s.id = "myselect";
s.setAttribute("onchange", "runThisFunc()");
//s.onchange = "runThisFunc()";
p.appendChild(s);
o = document.createElement("OPTION");
o.value = 1;
o.innerText = 1;
s.appendChild(o);
o = document.createElement("OPTION");
o.value = 2;
o.innerText = 2;
s.appendChild(o);
alert(document.body.innerHTML);
}
</script>
<body onload="init()">
<select name="mylist" onchange=runThisFunc()>
<option value='op1'>Option1</option>
<option value='op2'>Option2</option>
<option value='op3'>Option3</option>
</select>
<div id='mydiv'>
</div>
</body>
</html>
Cheers.
Jimmy.
I've played around with all the script setting in IE but still cant get it to work. If any one could have a quick look and see if they can spot a problem that would be great.
Here is my code.
<html>
<script language='javascript'>
function runThisFunc()
{
alert("HelloWorld");
}
function init()
{
p = document.getElementById("mydiv");
s = document.createElement("SELECT");
s.id = "myselect";
s.setAttribute("onchange", "runThisFunc()");
//s.onchange = "runThisFunc()";
p.appendChild(s);
o = document.createElement("OPTION");
o.value = 1;
o.innerText = 1;
s.appendChild(o);
o = document.createElement("OPTION");
o.value = 2;
o.innerText = 2;
s.appendChild(o);
alert(document.body.innerHTML);
}
</script>
<body onload="init()">
<select name="mylist" onchange=runThisFunc()>
<option value='op1'>Option1</option>
<option value='op2'>Option2</option>
<option value='op3'>Option3</option>
</select>
<div id='mydiv'>
</div>
</body>
</html>
Cheers.
Jimmy.