Newcomer19
07-16-2003, 03:29 PM
I need some help with the following code.
This script generates a scrollable list of items and works fine in IE. However there are two problems:
1. Once it reaches the end of the array, I use an alert to indicate end of file. Is there a way to make the scrolling stop when it reaches end of file and it just displays the last set of files?
2. Is there a simple enough way to make it work in Netscape 4+
I know Netscape does not support innerHTML.
Please help me.
==============================================
<table cellspacing="0" cellpadding="1" width="100%" bgcolor="#ffffff" border="0">
<tr><td width="100%">
<div id="oTableContainer"></div>
<script>
var direction=0;
var nextS=0;
var displayPerPage=5;
var myArray = new Array();
function fileMess(item1,item2,item3,item4,item5) {
this.item1 = item1;
this.item2 = item2;
this.item3 = item3;
this.item4 = item4;
this.item5 = item5;
myArray[myArray.length] = this;
}
function createfileMess() {
new fileMess("101","blah101","101","0","");
new fileMess("102","blah102","102","0","");
new fileMess("103","blah103","103","0","");
new fileMess("104","blah104","104","1","");
new fileMess("105","blah105","105","1","");
new fileMess("106","blah106","106","1","");
new fileMess("107","blah107","107","1","");
new fileMess("108","blah108","108","1","");
new fileMess("109","blah109","109","1","");
new fileMess("110","blah110","110","1","");
new fileMess("111","blah111","111","1","");
new fileMess("112","blah112","112","1","");
new fileMess("113","blah113","113","1","");
new fileMess("114","blah114","114","1","");
new fileMess("115","blah115","115","1","");
new fileMess("116","blah116","116","1","");
new fileMess("117","blah117","117","1","");
new fileMess("118","blah118","118","1","");
new fileMess("119","blah119","119","1","");
new fileMess("120","blah120","120","1","");
}
function displayfileMess(s)
{
var oTable = document.createElement("TABLE");
var oTHead = document.createElement("THEAD");
var oTBody0 = document.createElement("TBODY");
var oTBody1 = document.createElement("TBODY");
var oTFoot = document.createElement("TFOOT");
var oCaption = document.createElement("CAPTION");
var oRow, oCell;
var i, j;
var heading = new Array;
heading[0] = "item1";
heading[1] = "item2";
heading[2] = "item3";
heading[3] = "item4";
heading[4] = "item5";
// Insert the created elements into oTable.
oTable.appendChild(oTHead);
oTable.appendChild(oTBody0);
oTable.appendChild(oTBody1);
oTable.appendChild(oTFoot);
oTable.appendChild(oCaption);
// Set the table's border width and colors.
oTable.border=0;
oTable.bgColor="cccccc";
oTable.width="396";
oRow = document.createElement("TR");
oTHead.appendChild(oRow);
oTHead.bgColor = "cccccc";
// Create and insert cells into the header row.
for (i=0; i<5; i++)
{
oCell = document.createElement("TH");
oCell.innerText = heading[i];
oRow.appendChild(oCell);
}
// Create and insert rows and cells into the first body.
direction = s;
if (direction ==-1)
{
nextS = nextS-displayPerPage;
}
if (direction ==1){
nextS = nextS+displayPerPage;
}
if (nextS <=-displayPerPage)
{
nextS =0;
}
f=nextS+displayPerPage;
if (f>myArray.length)
{
f=myArray.length;
alert("end of files");
}
for (i=nextS; i<f; i++)
{
oRow = document.createElement("TR");
oTBody0.appendChild(oRow);
{
oCell = document.createElement("TD");
oCell.innerText = myArray[i].item1;
oRow.appendChild(oCell);
oCell = document.createElement("TD");
oCell.innerText = myArray[i].item2;
oRow.appendChild(oCell);
oCell = document.createElement("TD");
oCell.innerText = myArray[i].item3;
oRow.appendChild(oCell);
oCell = document.createElement("TD");
oCell.innerText = myArray[i].item4;
oRow.appendChild(oCell);
oCell = document.createElement("TD");
oCell.innerText = myArray[i].item5;
oRow.appendChild(oCell);
}
s=0;
}
// Insert the table into the document tree.
oTableContainer.appendChild(oTable);
}
createfileMess();
displayfileMess();
document.write("<table width=350><tr><td><input type=button value=previous onClick='oTableContainer.innerHTML=\"\"; displayfileMess(-1)'><input type=button value=next onClick='oTableContainer.innerHTML=\"\"; displayfileMess(1)'></td></tr></table>");
</script>
</td></tr></table>
This script generates a scrollable list of items and works fine in IE. However there are two problems:
1. Once it reaches the end of the array, I use an alert to indicate end of file. Is there a way to make the scrolling stop when it reaches end of file and it just displays the last set of files?
2. Is there a simple enough way to make it work in Netscape 4+
I know Netscape does not support innerHTML.
Please help me.
==============================================
<table cellspacing="0" cellpadding="1" width="100%" bgcolor="#ffffff" border="0">
<tr><td width="100%">
<div id="oTableContainer"></div>
<script>
var direction=0;
var nextS=0;
var displayPerPage=5;
var myArray = new Array();
function fileMess(item1,item2,item3,item4,item5) {
this.item1 = item1;
this.item2 = item2;
this.item3 = item3;
this.item4 = item4;
this.item5 = item5;
myArray[myArray.length] = this;
}
function createfileMess() {
new fileMess("101","blah101","101","0","");
new fileMess("102","blah102","102","0","");
new fileMess("103","blah103","103","0","");
new fileMess("104","blah104","104","1","");
new fileMess("105","blah105","105","1","");
new fileMess("106","blah106","106","1","");
new fileMess("107","blah107","107","1","");
new fileMess("108","blah108","108","1","");
new fileMess("109","blah109","109","1","");
new fileMess("110","blah110","110","1","");
new fileMess("111","blah111","111","1","");
new fileMess("112","blah112","112","1","");
new fileMess("113","blah113","113","1","");
new fileMess("114","blah114","114","1","");
new fileMess("115","blah115","115","1","");
new fileMess("116","blah116","116","1","");
new fileMess("117","blah117","117","1","");
new fileMess("118","blah118","118","1","");
new fileMess("119","blah119","119","1","");
new fileMess("120","blah120","120","1","");
}
function displayfileMess(s)
{
var oTable = document.createElement("TABLE");
var oTHead = document.createElement("THEAD");
var oTBody0 = document.createElement("TBODY");
var oTBody1 = document.createElement("TBODY");
var oTFoot = document.createElement("TFOOT");
var oCaption = document.createElement("CAPTION");
var oRow, oCell;
var i, j;
var heading = new Array;
heading[0] = "item1";
heading[1] = "item2";
heading[2] = "item3";
heading[3] = "item4";
heading[4] = "item5";
// Insert the created elements into oTable.
oTable.appendChild(oTHead);
oTable.appendChild(oTBody0);
oTable.appendChild(oTBody1);
oTable.appendChild(oTFoot);
oTable.appendChild(oCaption);
// Set the table's border width and colors.
oTable.border=0;
oTable.bgColor="cccccc";
oTable.width="396";
oRow = document.createElement("TR");
oTHead.appendChild(oRow);
oTHead.bgColor = "cccccc";
// Create and insert cells into the header row.
for (i=0; i<5; i++)
{
oCell = document.createElement("TH");
oCell.innerText = heading[i];
oRow.appendChild(oCell);
}
// Create and insert rows and cells into the first body.
direction = s;
if (direction ==-1)
{
nextS = nextS-displayPerPage;
}
if (direction ==1){
nextS = nextS+displayPerPage;
}
if (nextS <=-displayPerPage)
{
nextS =0;
}
f=nextS+displayPerPage;
if (f>myArray.length)
{
f=myArray.length;
alert("end of files");
}
for (i=nextS; i<f; i++)
{
oRow = document.createElement("TR");
oTBody0.appendChild(oRow);
{
oCell = document.createElement("TD");
oCell.innerText = myArray[i].item1;
oRow.appendChild(oCell);
oCell = document.createElement("TD");
oCell.innerText = myArray[i].item2;
oRow.appendChild(oCell);
oCell = document.createElement("TD");
oCell.innerText = myArray[i].item3;
oRow.appendChild(oCell);
oCell = document.createElement("TD");
oCell.innerText = myArray[i].item4;
oRow.appendChild(oCell);
oCell = document.createElement("TD");
oCell.innerText = myArray[i].item5;
oRow.appendChild(oCell);
}
s=0;
}
// Insert the table into the document tree.
oTableContainer.appendChild(oTable);
}
createfileMess();
displayfileMess();
document.write("<table width=350><tr><td><input type=button value=previous onClick='oTableContainer.innerHTML=\"\"; displayfileMess(-1)'><input type=button value=next onClick='oTableContainer.innerHTML=\"\"; displayfileMess(1)'></td></tr></table>");
</script>
</td></tr></table>