[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Set focus to table row in scrolling div

Posted on 2007-08-07
3
Medium Priority
?
10,793 Views
Last Modified: 2010-05-18
I have a table inside a scrolling div, I want to scroll to a specific row when the page is loaded and there the table is just 2 columns containing text. How can I do that?

Thanks in advance
0
Comment
Question by:JessyEzzy
  • 2
3 Comments
 
LVL 63

Expert Comment

by:Zvonko
ID: 19649157
How do you know the row? By row number or some id?
0
 
LVL 63

Accepted Solution

by:
Zvonko earned 200 total points
ID: 19649269
Her a scroll by row number:



<html>
<head>
<title>Zvonko &#42;</title>
<style>
#scrollDiv {
  height: 100px;
  width: 100px;
  overflow: scroll;
}
</style>
<script>
window.onload = function(){
  var row = document.getElementById("myTab").rows;
  row[6].scrollIntoView(false);
}
</script>
</head>
<body>
<div id="scrollDiv">
<table id="myTab" >
<tr><td>A</td><td>1</td></tr>
<tr><td>A</td><td>2</td></tr>
<tr><td>A</td><td>3</td></tr>
<tr><td>A</td><td>4</td></tr>
<tr><td>A</td><td>5</td></tr>
<tr><td>A</td><td>6</td></tr>
<tr><td>A</td><td>7</td></tr>
<tr><td>A</td><td>8</td></tr>
<tr><td>A</td><td>9</td></tr>
<tr><td>A</td><td>10</td></tr>
</table>
</div>
</body>
</html>





0
 
LVL 3

Author Comment

by:JessyEzzy
ID: 19650062
Yeah sure scrollIntoView I totally forgot about it :)
I'll be using row id coz the table will be generated dynamically so I guess I'll need a function like that
function scrollToRow(index)
{
    var row = document.getElementById("row" + index);
    row.scrollIntoView(false);
}

Thanks alot
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question