Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jul 2006
    Location
    Cork Ireland
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile Javascript to show what records your viewing eg 0 to 3 of 57.

    Hi All!

    I have designed a web page that has a previous and next button on it which displays three results at the time. This all works perfectly now thanks to the help i received on this forum but now i want to add an extra piece of functionality.

    I would like to display something like 'You are currently viewing 0 to 3 of 57 records'

    Below is the code i used to carry out the paging;

    If anyone has any ideas i would be delighted with their help. Even the correct name for this function would be usefull for me to do some research..

    Thanks,

    margaret

    Code:
    <SCRIPT>
    var intPosition=0;
    function ShowFirstThreeItems()
    {
        var i;
        i=1;
        for (i=1; i<=3; i++) 
        {
        eval('ItemRow'+i+'.style.display="block"');
        intPosition=i;
        
        }
    }
    function showNext()
    {
        
        var i;
       
       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"');
    }
    }
    
    
    </SCRIPT>

  • #2
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,467
    Thanks
    3
    Thanked 495 Times in 482 Posts
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
    
    <html>
    
    <head>
      <title></title>
    <SCRIPT>
    
    function zxcTableStep(zxcid,zxcdir,zxctxt){
     var zxcary=window['zxc'+zxcid];
     zxcary[0]=zxcary[0]+zxcdir;
     zxcary[0]=(zxcary[0]<1)?zxcary[0]=zxcary.length-1:(zxcary[0]==zxcary.length)?1:zxcary[0];
     var zxccnt=0;
     for (var zxc0=1;zxc0<zxcary.length;zxc0++){
      zxcdis=(zxc0==zxcary[0])?'':'none';
      for (var zxc1=1;zxc1<zxcary[zxc0].length;zxc1++){
       zxcary[zxc0][zxc1].style.display=zxcdis;
       zxccnt++;
      }
     }
     document.getElementById(zxctxt).innerHTML=zxcary[zxcary[0]][0]+' to '+(zxcary[zxcary[0]][0]+zxcary[zxcary[0]].length-2)+' of '+zxccnt;
    }
    
    function zxcTableInit(zxcid,zxcnu){
     var zxcary=window['zxc'+zxcid]=[1];
     var zxcrows=document.getElementById(zxcid).rows;
     for (var zxc0=0;zxc0<zxcrows.length;zxc0++){
      if (zxc0%zxcnu==0){ zxcary[zxcary.length]=[zxc0+1];  }
      zxcary[zxcary.length-1].push(zxcrows[zxc0]);
      if (zxc0>=zxcnu){
       zxcrows[zxc0].style.display='none';
      }
     }
    }
    
    </SCRIPT>
    
    </head>
    
    <body onload="zxcTableInit('Tst1',3);">
    <input type="button" name="" value="Fwd" onclick="zxcTableStep('Tst1',1,'Txt')"><input type="button" name="" value="Prev" onclick="zxcTableStep('Tst1',-1,'Txt')">
    <div id="Txt" >1 to 3 of 14</div>
    
    <table id="Tst1"cellpadding="0" cellspacing="0" border="1">
      <tr><td width="100">Row 1</td></tr>
      <tr><td width="100">Row 2</td></tr>
      <tr><td width="100">Row 3</td></tr>
      <tr><td width="100">Row 4</td></tr>
      <tr><td width="100">Row 5</td></tr>
      <tr><td width="100">Row 6</td></tr>
      <tr><td width="100">Row 7</td></tr>
      <tr><td width="100">Row 8</td></tr>
      <tr><td width="100">Row 9</td></tr>
      <tr><td width="100">Row 10</td></tr>
      <tr><td width="100">Row 11</td></tr>
      <tr><td width="100">Row 12</td></tr>
      <tr><td width="100">Row 13</td></tr>
      <tr><td width="100">Row 14</td></tr>
    </table>
    </body>
    
    </html>
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/


  •  

    Posting Permissions

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