Click to See Complete Forum and Search --> : next/prev navigation question


helpthenewbie:)
02-03-2003, 09:58 AM
hullo
got this nice little bit of code from this site and am trying to alter it slightly so i can use it. have changed the file names appropriately, but i think i need to edit as i don't use frames, so have taken the "parent.frames['body']." part off but don't know what to replace it with to get it to work, it works for 2 pages then dies on me (stops progressing) with no error, can anyone help? any help v much appreciated... (i realise this will be sooooo simple for most people here, so bare with me!)

<SCRIPT language=javascript type=text/javascript>
<!--
<!-- script created by : THeMaRTy -->
<!-- website: http://marty.excudo.net -->
var count=1;
// the array with the links
// you can add as many links as you like, as long as you keep the numbers succeeding
var link_array = new Array();
link_array[1] = 'main.html';
link_array[2] = 'twee.html';
link_array[3] = 'drie.html';
// skip fwd
function next()
{
if ((count + 1) >= link_array.length)
{
alert('That was the last page');
}
else
{
count = count + 1;
parent.frames['body'].document.location.href = link_array[count];
}
}
// skip back
function previous()
{
if ((count - 1) <= 0)
{
alert('This is the first page');
}
else
{
count = count - 1;
parent.frames['body'].document.location.href = link_array[count];
}
}
//-->
</SCRIPT>

khalidali63
02-03-2003, 10:30 AM
If you are not using frames then you just need to get rid of
parent.frames['body']. completely.

therefore this line

parent.frames['body'].document.location.href = link_array[count];

should be replaced with

document.location.href = link_array[count];

all of instances of it.

hope this helps

cheers

Khalid

helpthenewbie:)
02-03-2003, 03:09 PM
hi again
yep, already tried this, the first time you click on next it works with no errors then you click again to get to the next page and it just keeps loading the same page and the back button then just brings up the alert message which is meant for the first page, still no errors it just doesn't continue on.
this make sense?
ta 4 ur help & speedy response!

helpthenewbie:)
02-17-2003, 06:05 AM
any thoughts on this one??
still not sure what is going wrong here...
doh!
manda

cyberade
02-17-2003, 06:34 AM
You don't say whether the script is embedded in the page or part of a .js file but it sounds like the script is being invoked afresh at each page load. That means that your count will always be '1' - so 'next' will always take you to element 2 of the array then reset count to 1 so 'back' will always confirm that you're already at element 1 of the array.
Not sure how to fix it though - anyone else?
If I do think of something, I'll post it later.

HTH

cyberade
02-18-2003, 07:38 PM
I used the forums search function and found this link:

http://forums.webdeveloper.com/showthread.php?s=&threadid=4326

The last post in that thread should give you the answer you're looking for - i.e. pass the variable along with the URL. (In fact, just like the above link!)

Thanks to Khalid for this!