...

View Full Version : Loop to display records has an error! Can anyone see it?



Margaret101
09-05-2006, 04:09 PM
Hey all!!
I have written the code below which pages records perfectly for me. I added in a little extra bit of functionality which is: 'Showing x to y.'

However it is not looping through properly. When show first three items is called it displays 'Showing 1 to 3' which is correct but when you click next it still says 'Showing 1 to 3'. On the next click it moves through the records correctly and so on.

Also when you click back it jumps up three records before moving back a set of records the first time you click previous. again it works perfect after the first click...

I would be delighted if any one could see the problem.. Thanks

Mags




function ShowFirstThreeItems()
{
var i;
i=1;
var j=i+2;

strPageDetails="Showing items "+i+" to"+j;
for (i=1; i<=3; i++)
{
eval('ItemRow'+i+'.style.display="block"');
intPosition=i;
}

}

function showNext()
{

var i;
var tempint = intPosition+1;
var j=tempint+2;

PageDetails.innerText=strPageDetails;
strPageDetails="Showing items "+tempint+" to "+j;
for(i=(intPosition<=3)?1:intPosition-2;i<=intPosition+3;i++)
{
eval('ItemRow'+i+'.style.display="none"');
}
for (i=intPosition+1; i<=intPosition+3; i++)
{
eval('ItemRow'+i+'.style.display="block"');
}
intPosition=i-1;


}

function showPrev()
{
var i;
var firstEnd=intPosition-3; // Saves on calculating through each iteration.

for (i=intPosition; i>firstEnd; i--)
{
if (i==0) break;
eval('ItemRow'+i+'.style.display="none"');
}
intPosition=firstEnd;
var secondEnd=(firstEnd<3)?0:firstEnd-3; // Set end for second loop

for (i=firstEnd; i>secondEnd; i--)
{
eval('ItemRow'+i+'.style.display="block"');
}

PageDetails.innerText=strPageDetails;
strPageDetails="Showing items "+secondEnd+" to "+firstEnd;
}


</SCRIPT>

<script language="JavaScript">
var strPageDetails='';
ShowFirstThreeItems();
PageDetails.innerText=strPageDetails;

</script>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum