PDA

View Full Version : Automating next and previous


dreamxgirl
10-21-2004, 11:41 PM
I hope no one has put a request like this in yet - I tried searching the forum, but couldn't find anything.. Apologies if there are.

Ok...

I have created a very basic (still learning!)CBL template using DreamWeaver. When complete, I want to share this with the other people in my group, so that they can make their own CBLs.. Everything is going well except for the navigation bar. I am wanting to create a next and previous button, where they can literally go back one page and forward one page etc.

So I come up with the following code:


<SCRIPT LANGUAGE="JavaScript">
<!--
function go(prf) {
var text = self.location.href;
var pos = text.indexOf (prf);
var poslng = prf.length;
var num = text.substring(pos+poslng,pos+poslng+3) - 0 + dir;
num = (num < 10) ? "00" + num : ( (num < 100) ? "0" + num : num);
window.location.href = text.substring(0,pos+poslng) +
num +
text.substring(pos+poslng+3,text.length);
}
//-->
</SCRIPT>

From what I can tell - this should search dir with a number.
eg.
fire001.htm,
fire002.htm,
fire003.htm and lets it advance by following the numbers up to 999.

So - I am needing it to just follow the sequence in numbers, regardless of what the first letters of the cbl file is called.

Well.. it won't work.. Every time I view it in browser - nothing happens when I click on link. Why?

At the moment, I applied the template to fire001.htm and fire002.htm
The links on there are back and next (javascript:go(1) and javascript:go(-1)

Could someone please help me?? :confused:

Thanks!

Willy Duitt
10-22-2004, 12:04 AM
Kind of hard to tell what is going on without seeing the complete path but I would assume your problem lies within:

var num = text.substring(pos+poslng,pos+poslng+3) - 0 + dir;


If it helps, here is something simular I once wrote for an iframe that should not be hard to adapt to location.href... although you may need to add some additional checks to accomodate the leading zeros in 001, 010 ect... (although it would be much easier to begin counting at 1 and forget the leading zeros)


<script type="text/javascript">
<!--//
function changePage(number){
var firstNumber = 001;
var lastNumber = 999;
var content = document.getElementById('content');
var oldNumber = content.src.match(/(\d+)(?=\.)/);
var newNumber = RegExp.$1*1+number;

if(newNumber < firstNumber){ newNumber = lastNumber };
if(newNumber > lastNumber) { newNumber = firstNumber };
content.src = content.src.replace(/(\d+)(?=\.)/,newNumber);
document.getElementById('test').innerHTML = content.src;
}
//-->
</script>
</head>

<body>
<a href="#" class="link" onclick="changePage(-1)">Back</a>
<a href="#" class="link" onclick="changePage(+1)">Forward</a>
<div><iframe id="content" src="001.html"></iframe></div>
<div id="test"></div>


.....Willy

dreamxgirl
10-22-2004, 01:39 AM
Thanks!

I'll try it and let you know.


Ok...

i tried it, but because I don't know enough about javascript - I don't know if I did it right or not. As for the naming convention - well.. it doesn't have to be 001 etc..

I have attached a zip file, that contains my template, and two pages.

It seems every time I view them in a browser - nothing happens when I click on the link.

Willy Duitt
10-22-2004, 09:11 AM
That script was written to change an iframe source and needs a few modifications to fit your needs... I did not bother to do this for you previously because I was unsure if you were stuck on using the leading zeros which would affect what modifications were necassary...

Try this:


modified script removed by author
Look here (http://www.webdeveloper.com/forum/showthread.php?s=&threadid=47161) instead...


.....Willy