PDA

View Full Version : Page change with pagination code activate



alanwsl
10-22-2007, 10:58 PM
1) Script Title: Ajax Pagination script

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex17/ajaxpaginate/index.htm

3) Describe problem: I created 2 different pages (a.htm) and (b.htm). Both pages have the same ajax pagination script running on different categories.

I also created a hyperlink in (a.htm) to connect to (b.htm), working fine.
The problem is, my hyperlink in (a.htm) cannot call the function to jump to "pagination page 2" in (b.htm)

Does anyone know how to?

<a href="b.htm">
<a href="javascript:mypages.selectpage(1)">

Does not seems to work in this form. Is there anyway to combine this two?

ddadmin
10-23-2007, 02:00 AM
You'll need to pass some info via the URL or cookies to the target page containing the Pagination script to then tell it to run selectpage() with a certain value. The technique for doing this with another script is discussed here: http://www.dynamicdrive.com/forums/showthread.php?t=24920

In a nutshell though, instead of the default:


<script type="text/javascript">

var myajaxbook={} //arbitrary variable to hold page settings for this book
myajaxbook.page=["external.htm", "external2.htm", "external3.htm", "external4.htm"]
myajaxbook.selectedpage=0 //set page shown by default (0=1st page)

</script>

You'd have this instead:


<script type="text/javascript">

var param=window.location.href.match(/selectpage=(\d+)/i)
var paramvalue=RegExp.$1
if (/\d+/i.test(paramvalue)) //if URL parameter contains "?selectpage=integer"

var myajaxbook={} //arbitrary variable to hold page settings for this book
myajaxbook.page=["external.htm", "external2.htm", "external3.htm", "external4.htm"]
var param=window.location.href.match(/selectpage=(\d+)/i)
var paramvalue=RegExp.$1
if (/\d+/i.test(paramvalue)) //if URL parameter contains "?selectpage=integer"
myajaxbook.selectedpage=parseInt(paramvalue)
else
myajaxbook.selectedpage=0 //set page shown by default (0=1st page)

</script>

The link on page A would look something like the below:


<a href="b.htm?selectpage=1">

alanwsl
10-23-2007, 09:26 AM
DD should have a tag line call "YOU JUST CAN"T BELIEVE YOUR EYES"

I really cannot believe my eyes, it really works.

Thank you so much.

This problem has caught me a week (before i know DD). In just a day DD solved all of it.

Really good job:)

alanwsl
10-25-2007, 03:57 PM
Ok now jumping to a page is not a problem, but calling another set of book is?

Can you please show me how to call another set of book say (myajaxbook3) to load instead of showing the (myajaxbook) set when i call from an external url.

Thank you

ddadmin
10-26-2007, 01:28 AM
What "book" is loaded simply depends on how you configure it when it's called. So for example, you might have something like:


<script type="text/javascript">

var param=window.location.href.match(/selectpage=(\d+)/i)
var paramvalue=RegExp.$1
if (/\d+/i.test(paramvalue)) //if URL parameter contains "?selectpage=integer"

var myajaxbook3={} //arbitrary variable to hold page settings for this book
myajaxbook3.page=["page1.htm", "page2.htm", "page3.htm"]
var param=window.location.href.match(/selectpage=(\d+)/i)
var paramvalue=RegExp.$1
if (/\d+/i.test(paramvalue)) //if URL parameter contains "?selectpage=integer"
myajaxbook3.selectedpage=parseInt(paramvalue)
else
myajaxbook3.selectedpage=0 //set page shown by default (0=1st page)

</script>

Here I'm creating a book with 3 pages, and either selecting the page based on the URL parameter, or the 1st page by default.

alanwsl
10-26-2007, 07:41 AM
oops.. sorry i sould be more specific, i am just a beginner so sorry.
Here:...

I've created 3 books in url "z.htm" and in url "y.htm" i have 3 buttons,
1) <a href="z.htm?selectbook=myajaxbook1">
2) <a href="z.htm?selectbook=myajaxbook2">
3) <a href="z.htm?selectbook=myajaxbook3"> respectively.

so when i click on the button, it will call z.htm with the respective set of myajaxbook shown

so what code should i insert down here:-
<script type="text/javascript">

var myajaxbook1={} //arbitrary variable to hold page settings for this book
myajaxbook1.page=["page1.htm", "page2.htm", "page3.htm"]
myajaxbook1.selectedpage=0 //set page shown by default (0=1st page)

var myajaxbook2={} //arbitrary variable to hold page settings for this book
myajaxbook2.page=["page1.htm", "page2.htm", "page3.htm"]
myajaxbook2.selectedpage=0 //set page shown by default (0=1st page)

var myajaxbook3={} //arbitrary variable to hold page settings for this book
myajaxbook3.page=["page1.htm", "page2.htm", "page3.htm"]
myajaxbook3.selectedpage=0 //set page shown by default (0=1st page)

var mypages=new ajaxpageclass.bindpages(myajaxbook1, "pcontent", ["paginate-bottom"])

</script>

Thank you for your patient

ddadmin
10-26-2007, 10:23 AM
Please format any code in your post using the CODE tag. This makes it a lot easier to read it.

So are you actually looking to select a particular book via the URL parameter, or a particular page within a particular book as well? The code I had posted uses the URL parameter simply to select a particular page regardless of which book it's being used on. The code you posted:


1) <a href="z.htm?selectbook=myajaxbook1">
2) <a href="z.htm?selectbook=myajaxbook2">
3) <a href="z.htm?selectbook=myajaxbook3"> respectively.

Are you really asking something like:


1) <a href="z.htm?selectbook=myajaxbook1&selectpage=1">
2) <a href="z.htm?selectbook=myajaxbook2&selectpage=0">
3) <a href="z.htm?selectbook=myajaxbook3&selectpage=2">

?

alanwsl
10-26-2007, 12:24 PM
Sorry for the code. Anyway it's done. Thanks for your help

But another thing is:-

When i have a very large book say 200pages, then the pagination-link will be very long right?

I am thinking is there anyway to display just
<< 1 2 3 4 5 6 7 8 9 10 Next>>
So when i click 2
the link become
<< 2 3 4 5 6 7 8 9 10 11 Next>>
and when i click 3
the link become
<< 3 4 5 6 7 8 9 10 11 12 Next>>
and so on
the pagination-link will always have 10 numbers or maybe 5 numbers display no matter how many pages i have

is it possible

example website -
http://boardgamecafe.net/community/photos/boardgamecafe_net/picture875.aspx

which consist of < Previous 1 2 3 4 5 Next> only

and if possible i would like to display the number of page of how many pages like this example: -
"Page 3 of 911 (911 items)"

ddadmin
10-28-2007, 11:36 PM
Technically it's definitely possible, though the changes involved would be more than just a "Quick edit". The best I can do now is to consider adding this feature the next time the script is updated, probably in the next 3 weeks.

jgifford
06-11-2008, 08:39 PM
Has the feature for controlling large number of pages been added?

If so how do we implement this?

Thanks