Go Back   CodingForums.com > :: Server side development > ASP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-04-2007, 07:53 PM   PM User | #1
gilgalbiblewhee
Regular Coder

 
Join Date: Mar 2005
Posts: 735
Thanks: 4
Thanked 1 Time in 1 Post
gilgalbiblewhee is an unknown quantity at this point
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>
gilgalbiblewhee is offline   Reply With Quote
Old 07-05-2007, 02:09 PM   PM User | #2
Daemonspyre
Regular Coder

 
Join Date: Mar 2007
Posts: 505
Thanks: 1
Thanked 19 Times in 19 Posts
Daemonspyre is on a distinguished road
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>")
%>
__________________
Quote:
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.
Daemonspyre is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:10 PM.


Advertisement
Log in to turn off these ads.