I have code for a scrollable table that contains multiple rows and when you enter a specific row number in textbox the scroll is reset to vertical row position on table.
I now want to convert to a horizontal table instead as shown with single row and multiple cells and able to scroll to table cell position when a column index value is entered into textbox.
All the code is included
<div id="scroll-pane" style="width:200px; height:100px; overflow-x:scroll; overflow-x:hidden;">
<table id="tabscroll">
<tr><td>item 0</td>
<td>item 1</td>
<td>item 2</td>
<td>item 3</td>
<td>item 4</td>
<td>item 5</td>
<td>item 6</td>
<td>item 7</td>
<td>item 8</td>
<td>item 9</td>
<td>item 10</td></tr>
</table>
</div>
<input type="text" id="rowNum" />
<input type="button" id="submit" value="go!" />
var divEl = document.getElementById("scroll-pane");
var selectedTrEl = undefined;
function select(index) {
var trEl = divEl.getElementsByTagName("tr")[index];
if (selectedTrEl) {
selectedTrEl.className = "";
}
selectedTrEl = trEl;
selectedTrEl.className = "selected";
var scrollTo = selectedTrEl.offsetTop;
divEl.scrollTop = scrollTo;
}
select(9);
document.getElementById("submit").onclick = function () {
var rowNum = document.getElementById("rowNum").value;
if (rowNum && rowNum.match(/\D/)) {
alert("Integers only!");
return;
}
if (rowNum) {
select(parseInt(rowNum));
}
};