[Javascript] Navigating an Array of size 1000
Andrew Gibson
andyg at ihug.co.nz
Tue Mar 25 15:08:12 CST 2003
=============================================
Subject: [Javascript] Navigating an Array of size 1000
I have an array that contains 1000 items, my requirement is to navigate 10
items at once and next 10 the next time.
that is i have two buttons next and previous, on click of next show first 10
items, and keep on navigating the array.
===========================================
If you want to just display the items, look into putting the array items
into a table using the .innerText properties.
<table id=myTable>
<tr><td></td></tr>
<tr><td></td></tr>
<tr><td></td></tr>
<tr><td></td></tr>
<tr><td></td></tr>
<tr><td></td></tr>
<tr><td></td></tr>
<tr><td></td></tr>
<tr><td></td></tr>
<tr><td></td></tr>
</table>
<a href=javascript:showItems(0)>Start</a> | <a
href=javascript:showItems(10)>Next</a>
<script>
var curStart=0
// sample array
var myArray=new
Array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22)
function showItems(n) {
if(n!=0) // get starting point of items to show
{
curStart=curStart+n;
}
else
{
curStart=0 ;
}
var item=curStart
var tb=document.getElementById("myTable");
for (x=0;x<=9;x=x+1)
{
tb.rows[x].cells[0].innerText=myArray[item]
item=item+1
}
}
</script>
Andrew Gibson
More information about the Javascript
mailing list