views:

68

answers:

2

I have an html page with a header, a table containing 100 items and a footer.

When there is a search, I highlight the row containing the data.

However, if the highlighted row is row 75, the user has to scroll down to find it.

How can I automatically scroll to that row?

I did see scrollTO() but see it only takes axis points.

Any suggestions?

Thanks.

(Using cgi in C, html, css and javascript/jquery)

+1  A: 

You should be able to use scrollIntoView(). (It's on the DOM elements directly.)

Be aware that there are some layout situations where scrolling something on the page can cause IE6 and 7 to decide that random other stuff needs to be scrolled too.

Pointy
+2  A: 

try this:

<script>
function ScrollToElement(theElement){

  var selectedPosX = 0;
  var selectedPosY = 0;

  while(theElement != null){
    selectedPosX += theElement.offsetLeft;
    selectedPosY += theElement.offsetTop;
    theElement = theElement.offsetParent;
  }

 window.scrollTo(selectedPosX,selectedPosY);

}
</script>

<body onload="ScrollToElement(document.formName.elementName)">

sushil bharwani
i have edited my answer because after testing i found it wont work
sushil bharwani
@sushil bharwani: thank you, very nice.
Tommy