In the function below chld is null only in IE, in firefox the javascript works fine.
var div = document.createElement("div");
var divid = "dv" + num;
div.setAttribute("ID", divid);
div.setAttribute("value", num);
var _text = document.createElement("input");
_text.setAttribute("type", "text");
_text.setAttribute("id", "txtAsName" + num);
_text.setAttribute("name", "txtAsName" + num);
var lbl = document.createElement("label");
var _upload = document.createElement("input");
_upload.setAttribute("type", "file");
_upload.setAttribute("ID", "upload" + num);
_upload.setAttribute("name", "uploads" + num);
_upload.setAttribute("size", "80");
var hyp = document.createElement("a");
//hyp.setAttribute("style", "cursor:Pointer");
hyp.style.cssText='cursor:Pointer';
//hyp.setAttribute("onclick", "return RemoveDv('" + divid + "');");
hyp.onclick=function() {RemoveDv(divid);};
hyp.innerHTML = "Remove";
var br = document.createElement("br");
var _pdiv = document.getElementById("Parent");
div.appendChild(br);
div.appendChild(lbl);
div.innerHTML += ' ';
div.appendChild(_text);
div.innerHTML += ' ';
div.appendChild(_upload);
div.innerHTML += ' ';
div.appendChild(hyp);
_pdiv.appendChild(div);
….
Here is the remove function
function RemoveDv(obj) {
var p = document.getElementById("Parent");
var chld = document.getElementById(obj);
p.removeChild(chld);
}
Here is what the div tags look lie that I am trying to remove..
<div align="left" id="Parent">
<div ID="dv1" value="1">
<div ID="dv2" value="2">
….
Interestingly even when I add this line of code “for debug sake” chld1 is still null
var chld1 = document.getElementById("dv1");
UPDATE:
It seems that there is nothing wrong with the code itself. If I run the same code in ie off my local code chld gets set. But if I run this code off our dev server ie does not see the element.
Any ideas why this could be?
This is a long shot, but try changing the capital case ID attribute on the div to lower case id. I don’t have IE and can’t test this out myself right now…sorry