473,513 Members | 2,709 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

pagination code

45 New Member
hi,
i want pagination using java script actually i get data from db that all row will hidden when i click next it will show next two row and hide the present row.but i have problem to go next and prevoius
Expand|Select|Wrap|Line Numbers
  1. var count=0;
  2.     var rowcount=1;
  3.     function fnnext(totval)
  4.     {    
  5.         if(rowcount<=totval)
  6.         {
  7.                 if(count < totval)
  8.                 {        
  9.                 document.getElementById(count).style.display="none";
  10.                 count=count+1;
  11.                 document.getElementById(count).style.display="none";
  12.  
  13.                     for(loop=count+1;loop<count+3;loop++)
  14.                     {
  15.                         document.getElementById(loop).style.display="block";
  16.                     }
  17.                 count++;
  18.                 }
  19.         }
  20.         else
  21.         {
  22.             alert("End of the page")                    
  23.         }
  24.             rowcount=loop;
  25.     }
  26.  
  27.     function fnprevious(totval)
  28.     {    alert(count)
  29.         if(rowcount > 2)
  30.         {
  31.                 if(count > 2)
  32.                 {                
  33.                 document.getElementById(count).style.display="none";
  34.                 count=count+1;
  35.                 document.getElementById(count).style.display="none";
  36.  
  37.                     for(loop=count-2;loop>0;loop--)
  38.                     {
  39.                         document.getElementById(loop).style.display="block";
  40.                     }
  41.                 count--;    
  42.                 }
  43.         }
  44.         else
  45.         {
  46.             alert("First page")            
  47.         }    
  48.             rowcount=loop;
  49.         alert(loop)
  50.     }
  51.  
  52.  
Sep 17 '08 #1
1 2349
iam_clint
1,208 Recognized Expert Top Contributor
This is how I would do it.. example.
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <script>
  4. var current_disp=0;
  5. function fnNext() {
  6.     var SR=document.getElementsByName("SearchResults"); /*Get all the search results into an object array*/
  7.     if (SR.length==0) { SR=getAnyElementByName("DIV", "SearchResults"); }
  8.     if (current_disp==SR.length-1) { alert("End of the page"); return false; } /*Check if you are at the end of the file*/
  9.     if (SR[current_disp]) { /*if its an object*/
  10.         SR[current_disp].style.display="none"; /*hide current results*/
  11.         current_disp++; /*add 1 to current display*/
  12.         SR[current_disp].style.display="block"; /*show next results*/
  13.     }
  14. }
  15.  
  16. function fnPrev() {
  17.     var SR=document.getElementsByName("SearchResults"); /*Get all the search results into an object array*/
  18.     if (SR.length==0) { SR=getAnyElementByName("DIV", "SearchResults"); }
  19.     if (current_disp==0) { alert("Beginning of the page"); return false; } /*Check if you are at the end of the file*/
  20.     if (SR[current_disp]) { /*if its an object*/
  21.         SR[current_disp].style.display="none"; /*hide current results*/
  22.         current_disp--; /*add 1 to current display*/
  23.         SR[current_disp].style.display="block"; /*show next results*/
  24.     }
  25. }
  26.  
  27. function getAnyElementByName(eleTag, eleName) { //*my IE Work Around
  28.     var Element_Tag=document.getElementsByTagName(eleTag);
  29.     var Return_Array=Array();
  30.     var c=0;
  31.     for (var i=0; i<Element_Tag.length; i++) {
  32.         if (Element_Tag[i].getAttribute("name")==eleName) {
  33.             Return_Array[c]=Element_Tag[i];
  34.             c++;
  35.         }
  36.     }
  37.     return Return_Array;
  38. }
  39. </script>
  40. </head>
  41. <body>
  42. <div name="SearchResults" id="res0">Results 1<br>Results 2</div>
  43. <div name="SearchResults" id="res1" style="display: none;">Results 3<br>Results 4</div>
  44. <div name="SearchResults" id="res2" style="display: none;">Results 5<br>Results 6</div>
  45. <div name="SearchResults" id="res3" style="display: none;">Results 7<br>Results 8</div>
  46. <div name="SearchResults" id="res4" style="display: none;">Results 9<br>Results 10</div>
  47. <div name="SearchResults" id="res5" style="display: none;">Results 11<br>Results 12</div>
  48. <input type="button" onclick="fnPrev()" value="Prev"><input type="button" onclick="fnNext()" value="Next">
  49. </body>
  50. </html>
  51.  
Sep 17 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
1745
by: Faree | last post by:
I am workign on a news portal which needs paginaiton as usual.but all the code i got depends on the number of records that will come from database :( .it is working well too. But i need...
2
2299
by: Chris H | last post by:
I am having a problem with pagination, basically the problem is happening in the "PREV / NUMBERS / NEXT" links, it appears as if the reason is becasue the increment and decrement operators aren't...
11
2744
by: ste | last post by:
Hi there, Further to my recent posts where I've received excellent help from Rik and Jerry, I've ended up with an image gallery on my website that displays images in a table, 3 images per row. ...
1
1823
by: OceanBreeze | last post by:
I am new to .Net. I am using ASP 2.0 and C#. I want to pupolate a data grid programatically using the values obtained from a list conating domain objects. E.g., DAL.GetEmployee() returns a...
0
1625
by: OceanBreeze | last post by:
I am using C# Page_Laod function to populate a web page with a table populated with several records. The table, rows (containing values) are popuated programatically with the values obtained from...
1
6835
by: shalini jain | last post by:
Hi, I want to know how can we do pagination using XSL. There are number of tutorials available on pagination using PHP but nothing with XSL. i am really stuck with my code. Below is the code that...
16
2746
by: gnawz | last post by:
I have a pagination function I am using in a file called functions.php as below<? //Pagination functions function getPagingQuery($sql, $itemPerPage = 10) { if (isset($_GET) && (int)$_GET > 0) ...
1
3538
markrawlingson
by: markrawlingson | last post by:
Hello, For starters: Yes, I am new to asp.net, however I hold a good 9-10 years of experience working with classic asp and am only just now upgrading my skills. I'm picking asp.net up pretty...
4
3552
by: ArizonaJohn | last post by:
Hello, The code below works great. The user enters a name into an HTML form, the code looks up a table with that name, and then that table is displayed. I am trying to use pagination with it,...
2
2583
by: kkshansid | last post by:
this is my search page on which i am getting two parameters from previous page but the problem is that as soon as i click any other next pages my sql query fails as it doesnt get these two parameters...
0
7254
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7153
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7432
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5677
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5079
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3230
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3218
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1585
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.