I have been trying to do the following. Using JS I want to create an
input element (text box) and attach a event listener. I have done in
in two different ways. The first is using xml elements directly (as in
e4x) and the second using the dom method createElement (which is much
clunkier to write). I'd prefer the former. I've included a stripped
down example below.
It appears that when creating an input element using the line:
var inputBox = <input type="text" size="30" />
that it does not have the same properties as when it is created with:
var inputBox2 = document.createElement("input");
because when an event listener is attached using addEventListener, an
error is generated on the first, but not the second.
My thoughts on this are either
1. The namespace for the input element is not correct and whether input
can have a listener attached. However, my guess is that it would not
show up in the first div box.
2. There's a bug. I have tried this in the nightly trunk build of FF
(Minefeld 3.0a1). If it does seem like a bug, I can file it.
Peter
The code is below:
<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN"
"http://www.w3.org/Math/DTD/mathml2/xhtml-math11-f.dtd">
<html>
<head>
<title>Testing events and e4x</title>
<script type="text/javascript e4x=1;">
//<![CDATA[
onload = function()
{
var inputBox = <input type="text" size="30" />
inputBox.addEventListener("focus",function () {alert("hi");},
false);
document.getElementById("out").innerHTML = <form>{inputBox}</form>;
}
//]]>
</script>
</head>
<body>
<h1>Testing events and e4x</h1>
<div id="out"></div>
</body>
</html>