Click to See Complete Forum and Search --> : "Error: d.getElementById[i] has no properties"
Jaguwar
11-13-2003, 09:19 AM
I am trying to create a tooltip compatible with Netscape 6+ and IE. It uses a combination of Javascript and PHP generated ID's. Part of the Javascript is below.
function locateObject(n,d) { //v3.0
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
{if(!(x=d[n])&&d.getElementById) x=d.getElementById[n];
alert(d.getElementById[n]);
for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.getElementById&&i<d.getElementById.length;i++)
x=locateObject(n,d.getElementById[i].document);
}
}
My problem is, the "alert" shows d.getelementById[i] returns undefined in both browsers. I think if I solve this issue, I'll be able to figure out why the tooltip doesn't show up in Netscape. I never was very good with Javascript.
Let me know if you need more info. Thanks!
Jaguwar
11-13-2003, 10:02 AM
function locateObject(n, d) { //v3.0
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n];
for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=locateObject(n,d.layers[i].document); return x;
}
As you can see, I replace d.all with d.getElementById. This works in IE, but not in Netscape. Perhaps there would have been a better way to do this so it works across both browsers?
migwich
11-13-2003, 12:29 PM
Maybe I'm misunderstanding this but isn't it returning a "No Properties" Error because " alert(d.getElementById[n]);" does not specify any properties?
( d.getElementById[n].someProperty )
What type of arguments would you pass?
locateObject('???', this???)
Jaguwar
11-13-2003, 01:32 PM
I'm using the Alert as a debugging tool (normally that particular bit of code wouldn't be there at all). In an effort to debug, I found that d.getElementById[i] has no properties. The function should have returned such a value at that point, which would now be assigned to x:
{if(!(x=d[n])&&d.getElementById) x=d.getElementById[n];
I suppose I could have debugged with alert(x);, but I'm not that clever. :-)
On the LocateObject function, it's called within another function called showTooltip. Here's the part of that code that uses locateObject() (note: for clarity, I've inserted a lot of line breaks here):
locateObject(object).style.top=document.body.scrollTop+event.clientY+20
locateObject(object).innerHTML=
'<table style="font-family: Tahoma, Arial, Helvetica, sans-serif;
font-size: 11px;
border: '+bordercolor+';
border-style: solid;
border-top-width: 1px;
border-right-width: 1px;
border-bottom-width: 1px;
border-left-width: 1px;
background-color: '+backcolor+'"
width="10"
border="0"
cellspacing="1"
cellpadding="1">
<tr>
<td nowrap>
<font style="font-family: Tahoma, Arial, Helvetica, sans-serif;
font-size: 11px;
color: '+textcolor+'">
'+unescape(tipContent)+'</font>
</td>
</tr>
</table> '
if ((e.x + locateObject(object).clientWidth) >
(document.body.clientWidth + document.body.scrollLeft))
{
locateObject(object).style.left = (document.body.clientWidth + document.body.scrollLeft) -
locateObject(object).clientWidth-10;
}
else
{
locateObject(object).style.left=document.body.scrollLeft+event.clientX
}
locateObject(object).style.visibility="visible"
}
In the actual page, the href tag makes a call to the showTooltip function, which needs locateObject to determine what
it's showing.
If that didn't make sense, let me know how I can help clear it up. I'm not always very good at explaining what I need, please bear with me! :confused:
Oh! I forgot to mention, "alert(d.getElementById[n]);" returns undefined.
Jaguwar
11-14-2003, 08:39 AM
bump
migwich
11-14-2003, 11:22 AM
I have to admit, I can't make heads or tails of this one. Probably since I'm no OOP guru. Without seeing the actual page in it's environment I'm not sure what I'm looking at.
Have you tried looking into getElements Arrays? This might help. Good luck!
http://wsabstract.com/dhtmltutors/domattribute2.shtml