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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get Screen Position of Textbox 1

Status
Not open for further replies.

checkai

Programmer
Jan 17, 2003
1,629
US
I need to get the X and Y coordinates of a textbox that embedded within a table...

any suggestions?

"...we both know I'm training to become a cagefighter...see what happens if you try 'n hit me..."
 

Relative to the table? To the browser? To the screen?



[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]
[banghead]

 

Sorry - I didn't see the title!

I know there's a post that did this... I'll try and hunt it down.

Dan


[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]
[banghead]

 
Evidently you're asking for more than just the properties, since I supplied the same answer in another forum. Here's a complete script:

Code:
function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

Just pass in the object whose position you're curious about, to both of these scripts. They'll return the element's current left (horizontal) and top (verical) positions, respectively.

Thomas D. Greer

Providing PostScript & PDF
Training, Development & Consulting
 
Excellent! Thanks Tgreer!

"...we both know I'm training to become a cagefighter...see what happens if you try 'n hit me..."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top