Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

probems getting the id from a anchor

Status
Not open for further replies.

fredes65

Programmer
Mar 2, 2002
9
AU
Im trying to intergrate a user defined function that gets the xy positions of an anchor into a dhtml menu script. the probem is that it doesnt seem to regognise either the id of the anchor or maybe doesnt load the function script. Im not sure! here is a simpified version of what Im trying to do
<script file = getpos.js>
<script file = menu.js>
<script>
new menu(pos,height, width);
</script>

<a href=&quot;#&quot; id=&quot;test&quot; name=&quot;test&quot; onmouseover=&quot;menu(menu)&quot;>

In my getpos.js Im adding the getpos function

getpos = getanchorposition(anchorid);

and it doesnt work. how do I bring in the id of the anchor? Any help appreciated!

Cheers
Fred
 
shouldn't it be:
<script src=&quot;whatever.js&quot;>
?
hope it helps Suceess, thats the way you spell success!
Got a question? Ask IMOZRMY!
 
Here's a slightly enchanced script that I posted not so long ago (look thread216-221307). It shows you the top/left and wifth/height of any page element:

<script>

function elemHeight(elemName) {

if (document.layers)
h = eval(&quot;document.layers[&quot; + elemName + &quot;].document.height&quot;)

else if (document.getElementById)
h = eval(&quot;document.getElementById('&quot; + elemName + &quot;').offsetHeight&quot;)

return(h);
}

function elemWidth(elemName) {

if (document.layers)
w = eval(&quot;document.layers[&quot; + elemName + &quot;].document.width&quot;)

else if (document.getElementById)
w = eval(&quot;document.getElementById('&quot; + elemName + &quot;').offsetWidth&quot;)

return(w);
}


function elemTop(elemName) {

if (document.layers)
t = eval(&quot;document.layers[&quot; + elemName + &quot;].document.pageY&quot;)

else if (document.getElementById)
t = eval(&quot;document.getElementById('&quot; + elemName + &quot;').offsetTop&quot;)

return(t);
}


function elemLeft(elemName) {

if (document.layers)
l = eval(&quot;document.layers[&quot; + elemName + &quot;].document.pageX&quot;)

else if (document.getElementById)
l = eval(&quot;document.getElementById('&quot; + elemName + &quot;').offsetLeft&quot;)

return(l);
}


function elemProps(elemName) {

w = &quot;width= &quot; + elemWidth(elemName);
h = &quot;height= &quot; + elemHeight(elemName);
t = &quot;top= &quot; + elemTop(elemName);
l = &quot;left= &quot; + elemLeft(elemName);

dims = &quot;element name: &quot; + elemName + &quot;\n\n&quot; + w + &quot;; &quot; + h + &quot;\n&quot; + t + &quot;; &quot; + l;

return(dims)
}

</script>

To make it compatible with IE4 change this:
[tt]if (document.getElementById)[/tt]
to this:
[tt]if ( (document.getElementById) ||
(document.all) ) [/tt]

To see the properties of any block element or link add this:
<a href=&quot;#&quot; id=&quot;test&quot; name=&quot;test&quot; onmouseover=&quot;alert(elemProps('test'))&quot;>
or
<div id=&quot;first&quot; style=&quot;border: solid 1px black; width:200px&quot; onclick=&quot;alert(elemProps('first'))&quot;>b l o c k <br> c o n t e n t</div>

Tested in Opera 6, IE5 and Netscape 6.2
It may be also useful for others. You are free use it as it is, or adjust for your specific needs.

good luck
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top