You're here: Snippet Directory » HTML/JavaScript (65)
Language:

Multi Page

Language: English
Programming Language: JavaScript
Published by: aimper [not registered]
Last Update: 5/15/2006
Views: 423

Description

this function write in an html document a list of pages containing a fixed number of elements, every one of which can be choosen selecting the appropriate page.

Code

1 ///////////////////////////////////////////////////////////////// 2 // 3 // Parametri 4 // input: 5 // total numero totale di records 6 // current pagina corrente 7 // forpage numero di records per pagina 8 // url URL di destinazione al quale verr 9 // aggiunta la query string ?pagina=xx 10 // numpagineindice numero di pagine che il navigatore 11 // visualizzer. 12 // Es. con numpagineindice=10 e total=16 si avr, 13 // se la pagina corrente minore di 10, lo 14 // schema seguente: 15 // - 1 2 3 4 5 6 7 8 9 10 .. 16 16 // se la pagina > di 10 si avr invece: 17 // - 11 12 13 14 15 16 18 // numpagineindice=0 visualizza nel navigatore 19 // tutte le pagine disponibili; 20 // numpagineindice=10 il valore di default. 21 // 22 ///////////////////////////////////////////////////////////////// 23 24 function multipage(total,current,forpage,url,numpagineindice) { 25 var visnumpages=numpagineindice + "" != "undefined" ? numpagineindice : 10; 26 var numpages=parseInt(total / forpage); 27 current=current + 0 != 0 ? current : 1; 28 if (total % forpage != 0) numpages++; 29 var start,end; 30 if (visnumpages==0) { 31 start=1; 32 end=numpages; 33 } else { 34 var fact=parseInt( (current -1 )/ visnumpages); 35 if (isNaN(fact)) fact=0; 36 start = 1 + (visnumpages * fact); 37 end = start + visnumpages - 1; 38 if (end > numpages) end = numpages; 39 } 40 //caso nullo: start uguale a end 41 if (start==end) return; 42 43 if (url.search(/[?]/) != - 1) 44 url += "&"; 45 else 46 url += "?"; 47 48 var link="<A HREF=\"" + url + "pagina="; 49 document.writeln("<CENTER>"); 50 //alert("start=" + start); 51 //alert("end=" + end); 52 if (current != 1) { 53 var prev=parseInt(current) - 1; 54 document.writeln(link + prev + "\">"); 55 document.writeln("<FONT SIZE=2>[&lt;&lt; Precedente]</FONT>"); 56 document.writeln("</A>"); 57 document.writeln("&nbsp;&nbsp;"); 58 } 59 60 for (var i=start;i<=end;i++) { 61 62 if (current==i) 63 document.writeln("<B>") 64 else 65 document.writeln(link + i + "\">"); 66 document.writeln(i); 67 if (current==i) 68 document.writeln("</B>"); 69 else 70 document.writeln("</A>"); 71 if (i < end) document.writeln(" - "); 72 } 73 74 if (end < numpages) { 75 document.writeln(" - "); 76 document.writeln("... "); 77 document.writeln(link + numpages + "\">"); 78 document.writeln(numpages); 79 document.writeln("</A>"); 80 } 81 82 if (current != numpages) { 83 document.writeln("&nbsp;&nbsp;"); 84 var next=parseInt(current) + 1; 85 document.writeln(link + next + "\">"); 86 document.writeln("<FONT SIZE=2>[Seguente &gt;&gt;]</FONT>"); 87 document.writeln("</A>"); 88 } 89 document.writeln("</CENTER>"); 90 } 91 92 93 94

No comments avaiable

Add a comment

Name *  

Email (won't be displayed) *    

Website  

Comment *  

Sicherheitscode Security Code *    

RSS