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
    Regular Coder
    Join Date
    Mar 2005
    Posts
    735
    Thanks
    4
    Thanked 1 Time in 1 Post

    paging with JavaScript and ASP "Next" "Previous"

    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:

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

    Code:
    	function prevLocation() {
    		document.write(location.pathname);
    		window.location="pg_0001<%'1%>.asp";
    	}
    	function nextLocation() {
    		document.write(location.pathname);
    		window.location="pg_0001<%'1%>.asp";
    	}
    Code:
    <a href="#" onclick="prevLocation();">Previous Page</a>
    <a href="#" onclick="nextLocation();">Next Page</a>

  • #2
    Regular Coder
    Join Date
    Mar 2007
    Posts
    505
    Thanks
    1
    Thanked 19 Times in 19 Posts
    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:

    Code:
    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:

    Code:
    <%
    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>")
    %>
    To say my fate is not tied to your fate is like saying, 'Your end of the boat is sinking.' -- Hugh Downs
    Please, if you found my post helpful, pay it forward. Go and help someone else today.


  •  

    Posting Permissions

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