SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: table/div scrollbar problem

  1. #1
    SitePoint Member
    Join Date
    Sep 2005
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question table/div scrollbar problem

    I have a table with a list of selectable rows. The table will scroll (due to a div tag) after a certain number of rows are inserted. I created a function which will allow the user to arrow-key up and down the list but I have one problem. Pressing an arrow key causes the scrollbar to also move. Is there a way to make that scrollbar not move except when either the top or bottom of the displayed list is reached (like in a Select listbox with a scrollbar)? Your help will be greatly appreciated.
    Below is the code which demonstrates the problem.

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script language="JavaScript">
    var curSelected = null;

    function rowFocus(row) {
    tblIcd9.rows[row].style.backgroundColor = 'blue';
    tblIcd9.rows[row].style.color = 'white';
    if (curSelected != null)
    {
    tblIcd9.rows[curSelected].style.backgroundColor = '';
    tblIcd9.rows[curSelected].style.color = '';
    }
    curSelected = row;
    }
    function rowArr() {
    var arrKey = event.keyCode;
    if ((arrKey == 38) && (curSelected > 0)) {
    rowFocus(curSelected-1);
    return;
    }
    if ((arrKey == 40) && (curSelected < (tblIcd9.rows.length-1))) {
    rowFocus(curSelected+1);
    return;
    }
    }
    </script>
    </head>

    <body onload="rowFocus(0);tblIcd9.focus();">
    <form name="frmLuIcd9">
    <table width="100%" height=100 border="0" bgcolor="#FFCC66" id="tblProb">
    <tr>
    <td width=100% height=20%>
    <div STYLE="overflow: auto; width: 100%; height: 100%" >
    <table width=100% height=100% border=0 cellpadding=0 cellspacing=0 id="tblIcd9" style="table-layout:fixed; background-color: white" onKeyDown="rowArr(this);" >
    <tbody id="myTbody">
    <tr onClick="rowFocus(1);"><td width=20%>code 1</td><td width=80%>desc 1</td></tr>
    <tr onClick="rowFocus(2);"><td width=20%>code 2</td><td width=80%>desc 2</td></tr>
    <tr onClick="rowFocus(3);"><td width=20%>code 3</td><td width=80%>desc 3</td></tr>
    <tr onClick="rowFocus(4);"><td width=20%>code 4</td><td width=80%>desc 4</td></tr>
    <tr onClick="rowFocus(5);"><td width=20%>code 5</td><td width=80%>desc 5</td></tr>
    <tr onClick="rowFocus(6);"><td width=20%>code 6</td><td width=80%>desc 6</td></tr>
    <tr onClick="rowFocus(7);"><td width=20%>code 7</td><td width=80%>desc 7</td></tr>
    <tr onClick="rowFocus(8);"><td width=20%>code 8</td><td width=80%>desc 8</td></tr>
    <tr onClick="rowFocus(9);"><td width=20%>code 9</td><td width=80%>desc 9</td></tr>
    <tr onClick="rowFocus(10);"><td width=20%>code 10</td><td width=80%>desc 10</td></tr>
    <tr onClick="rowFocus(11);"><td width=20%>code 11</td><td width=80%>desc 11</td></tr>
    </tbody>
    </table>
    </div>
    </td>
    </tr>
    </table>
    </form>
    </body>
    </html>

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Portsmouth UK
    Posts
    1,476
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •