...

View Full Version : paging with JavaScript and ASP "Next" "Previous"



gilgalbiblewhee
07-04-2007, 07:53 PM
I have a 700 page website paged pg_0001 - pg_0700. And I figure to my knowledge in JavaScript and ASP ( unless you have an easier way ) I want to first read the existing pathname:


document.write(location.pathname);
Then somehow add +1 ( next page ) to the string or -1 ( previous page )


function prevLocation() {
document.write(location.pathname);
window.location="pg_0001<%'1%>.asp";
}
function nextLocation() {
document.write(location.pathname);
window.location="pg_0001<%'1%>.asp";
}


<a href="#" onclick="prevLocation();">Previous Page</a>
<a href="#" onclick="nextLocation();">Next Page</a>

Daemonspyre
07-05-2007, 02:09 PM
Change your onclick to say prevLocation(1) and nextLocation(1). Then you will need to update the "1" every time you change pages.

Then, in your Javascript:


function prevLocation(ind) {
document.write(location.pathname);
window.location="pg_000" + (ind-1) + ".asp";
}
function nextLocation(ind) {
document.write(location.pathname);
window.location="pg_000" + (ind+1) + ".asp";
}



If you wanted to do this with ASP instead, just change your JS functions to be ASP:


<%
thisPage = mid(Request.ServerVariables("SCRIPT_NAME"),InStr(Request.ServerVariables("SCRIPT_NAME"),"pg_")+3,4)
' the above code will set variable thisPage = numeric name of the page. You may need to change this slightly based on testing.
'
thisPage = cInt(thisPage) 'ensures this is an integer
'
'
response.write("<a href=""#"" onclick=""pg_" & thisPage-1 & ".asp"">Previous Page</a>")
response.write("<a href=""#"" onclick=""pg_" & thisPage+1 & ".asp"">Next Page</a>")
%>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum