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

Finding page position of Form Elements

Status
Not open for further replies.

ashorton

Programmer
Mar 1, 2001
24
GB
When displaying a popup layer any Select boxes below the layer are showing through.

I am trying to find a method by which I can obtain the coordinates of each select box and match it to the layer position and area then hide only those select boxes that are covered.

 
I have tried to use .offsetLeft and .offsetTop but they always return a value of 1 or Nan.

When I create each Select element I set its ID to "Pselect_"+selectCount then:

for(var i=0;i<selectCount;i++)
{
elem=document.getElementById(&quot;Pselect_&quot;+i);

alert(elem.offsetLeft);
}

I am sure that I have read some where that to access positions you need to setup a style sheet for the element which includes 'left:' and 'top:'

 
no, in IE you do not need to go through the bother of absolutely positioning elements to find there exact position, you just need to get a valid reference to the object, try this page for instance:

<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>
<html>
<head>
<title>Untitled</title>
</head>
<body>
<br><br><br><br><br>
<select id=&quot;seltest&quot;>
<option>
<option>
</select>
<script>
alert(document.getElementById(&quot;seltest&quot;).offsetTop)
</script>
</body>
</html>

this script alerts is top position... jaredn@eae.net -
 
That works fine.

My code however still returns a value of either 1 or 2. The Select elements I am using are within a series of tables. I think I may need to use 'parentOffset' to calculate the exact location. I am not sure how this works at the moment. I will have a play and post my result.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top