PDA

View Full Version : IE 6 not recognizing my input.setAttribute(event, function()).


rptodd1
11-02-2006, 03:43 PM
here is the DOM scripting I used to create an input element and its attributes. IE6 see everything if you believe innerHtml, but doesnot react to the onblur event. How can I fix this?

// myInput attributes
var myInput = document.createElement("input");
myInput.setAttribute("type","text");
myInput.setAttribute("maxlength","12");
myInput.setAttribute("size","12");
myInput.setAttribute("id","myId");
myInput.setAttribute("name","myId");
myInput.setAttribute("onblur","changeDisplay()");

jkd
11-02-2006, 07:35 PM
IE basically shortcuts element.setAttribute("property", "value") to element[property] = "value", which means:

element.setAttribute("onblur", "doSomething()")

is transformed to:

element.onblur = "doSomething()";


Which doesn't quite work. It is best to just use DOM HTML properties and events when possible:

input.type = "text";
// ...
input.onblur = doSomething;