T
tapuleo
I'm creating a select tag, with options on the fly, and the events
(onclick, onchange, onkeydown) are not firing at all in Internet
Explorer. I tried IE 6 and 7...no luck. This all works fine in
Firefox.
Is there some trick to getting this to work in IE? Here's a short
example. If you click the button, the select (listbox) appears, but
no events fire.
------------------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled 1</title>
<script language="javascript" type="text/javascript">
function go()
{
var sel = document.createElement('select');
// hack to make IE show listbox, not dropdown
sel.length = 10; sel.length = 0;
sel.setAttribute("id","wsrListBox");
sel.setAttribute("size","10");
// try to set event ***NEVER FIRES in IE***
sel.setAttribute("onclick","alert(1);");
sel.options[0] = new Option("one","1");
sel.options[1] = new Option("two","2");
document.body.appendChild(sel);
}
</script>
</head>
<body>
<form>
<button onclick="go();return false;">Go!</button>
</form>
</body>
</html>
(onclick, onchange, onkeydown) are not firing at all in Internet
Explorer. I tried IE 6 and 7...no luck. This all works fine in
Firefox.
Is there some trick to getting this to work in IE? Here's a short
example. If you click the button, the select (listbox) appears, but
no events fire.
------------------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled 1</title>
<script language="javascript" type="text/javascript">
function go()
{
var sel = document.createElement('select');
// hack to make IE show listbox, not dropdown
sel.length = 10; sel.length = 0;
sel.setAttribute("id","wsrListBox");
sel.setAttribute("size","10");
// try to set event ***NEVER FIRES in IE***
sel.setAttribute("onclick","alert(1);");
sel.options[0] = new Option("one","1");
sel.options[1] = new Option("two","2");
document.body.appendChild(sel);
}
</script>
</head>
<body>
<form>
<button onclick="go();return false;">Go!</button>
</form>
</body>
</html>