gautam_reddyc
asked on
'name' is null or not an object
Hello I continuously keep getting this error in IE, while everything works in FF. I am trying to rename elements while I swap rows. All my elements have IDs. All elements except for divs, do not have names, so I get all elements by tag name from a row and perform my processing. But here in IE it gives me a problem when I try to replace name, for elements where name is null, I have a condition to prevent making any change, but this error pops up at the condition. Is there any way around for this problem??
var row= document.getElementById(row.id);
var elems = row.getElementsByTagName('*');
var r = explodeArray(row.id, "_");
var vtLineNum = Number(r[1]);
var vtName = r[0];
for(var i in elems)
{
if(elems!=null && elems[i]!=null && elems[i].id!=null && elems[i].id!='')
{
document.write(elems[i].name+"<br>");
elems[i].id = replaceNum(elems[i].id, vtLineNum);
if(elems[i].name !=null && elems[i].name !='')
{elems[i].name = replaceNum(elems[i].name, vtLineNum);}
if(elems[i].id.match("div"+vtName+'_'))
{
var children = document.getElementById(elems[i].id).childNodes;
for(var i in children)
{
if(children[i].href != null)
{
children[i].href = replaceNum(children[i].href, vtLineNum);
}
}
}
}
}
which line is giving this error?
ASKER
Line 12!! where the if condition checks if the name attribute is not null.
ASKER
it is giving me the error "undefined is null or object"?? It works find in FF. I have attached the changed code. I have used getAttribute function to get data and setAttribute to set data. I am getting the error at the if loop condition where it checks if the attribute is not equal to null.
function swapElemData(row)
{
swapLineData(row);
var row= document.getElementById(row.id);
var elems = row.getElementsByTagName('*');
var r = explodeArray(row.id, "_");
var vtLineNum = Number(r[1]);
var vtName = r[0];
for(var i in elems)
{
if(elems!=null && elems[i]!=null && elems[i].id!=null && elems[i].id!='')
{
elems[i].id = replaceNum(elems[i].id, vtLineNum);
if(elems[i].getAttribute('name') !=null && elems[i].getAttribute('name') !='')
{elems[i].setAttribute(('name'), replaceNum(elems[i].getAttribute('name'), vtLineNum));}
if(elems[i].id.match("div"+vtName+'_'))
{
if(document.getElementById(elems[i].id) !=null)
{
var children = document.getElementById(elems[i].id).childNodes;
for(var i in children)
{
if(children[i].href != null)
{
children[i].href = replaceNum(children[i].href, vtLineNum);
}
}
}
}
}
}
}
again, which line number?
all the elements will not have name attribute assigned to them
all the elements will not have name attribute assigned to them
ASKER
line 14!! yes you are right, how would I know if the element has the attribute??
can you alert these 2 statements
alert(elems[i])
alert(elems[i].id)
alert(elems[i].getAttribut e('name'))
alert(elems[i])
alert(elems[i].id)
alert(elems[i].getAttribut
ASKER
I know this is embarrasing, but IE is giving me the error "permission denied" everything was working till now, atleast giving me errors in logic. Now it pops an error at line 9 and tells me permission denied!! Who the hell are Microsoft helping with their senseless rules!!
<<Who the hell are Microsoft helping with their senseless rules!!>>
priceless :)...try closing your browser and start again.
priceless :)...try closing your browser and start again.
ASKER
Umm no luck, I have restarted my laptop, it gives me the same error. I actually am developing on a linux system and testing on a windows system which is in the same network. Is that ok, or could that be an issue??
yes, it should be ok
When it says 'permission denied', does it give any hint on which line?
When it says 'permission denied', does it give any hint on which line?
ASKER
Yes!! it is giving me an error at line 9 and an arrow points towards the variable elems!! I have also checked if elems was null, it is not null, but I still get the same permission denied error!!
ASKER
Ok one thing that I know now is "elems" is an array object and I am able to get its length. I have tried using for in loop, for loop and while to print out its elements but all I get back is permission denied. When I do not traverse through the array object "elems", everything works fine, but when I try to traverse through that array, I am getting the error.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Can you try this for fun
if(elems[i] && elems[i].id)
if(elems[i] && elems[i].id)