Forward-Back menu bar in frames - numbered set of pages

C

Chris

I have a script that will navigate back and foreward using a form. The
files it navigates are named: bg1.html, bg2.html, bg3.html, etc.

This is happening in a frameset, where my BACK and FORWARD buttons are
in one frame, and the content pages are in another (main).

I can get read the current page location in the frame "main", but it
is not working (getpagenumber)- it should give the current page
number, and use that number to tell the rest of the script where Back
and Foreward is. The current page is "bg1.html"

My script is below, followed by the form that will use it. Any help or
advice would be appreciated:

<script language="JavaScript">
<!--
function getpagenumber() {
var otherpage = parent.main.location.href;
var pagenumber =
otherpage.substring(otherpage.length-3,otherpage.length);
return pagenumber - 0;
}

function goForward() {
var page = getpagenumber();
if (page < 100)
parent.main.location.href = 'bg' + pad(page + 1,3) + '.html';
}
function goBackward() {
var page = getpagenumber();
if (page > 1)
parent.main.location.href = 'bg' + pad(page - 1,3) + '.html';
}
function pad(number,length) {
var str = '' + number;
while (str.length < length)
str = '0' + str;
return str;
}
//--></script>




<form>
<input type="button" value="Back" onClick="goBackward()">
<input type="button" value="Forward" onClick="goForward()">
</form>
 
L

Lee

Chris said:
I have a script that will navigate back and foreward using a form. The
files it navigates are named: bg1.html, bg2.html, bg3.html, etc.
<script language="JavaScript">
<!--
function getpagenumber() {
var otherpage = parent.main.location.href;
var pagenumber =
otherpage.substring(otherpage.length-3,otherpage.length);
alert(pagenumber);

return pagenumber - 0;
}

Ignoring the problems involved with frames and the fact that
your <script> tag and comment lines are out of date, the first
step in debugging this script should be to add an alert() as
shown above to see what value you're getting for pagenumber.
That should tell you what you need to fix.
 
R

Richard Cornford

Chris wrote:
... named: bg1.html, bg2.html, bg3.html, etc.
<script language="JavaScript">
<!--

The usual comments about the deprecated language attribute and the
outdated HTML comment script hiding practice applies to the above.
function getpagenumber() {
var otherpage = parent.main.location.href;
var pagenumber =
otherpage.substring(otherpage.length-3,otherpage.length);

This substringing operation should return the last 3 characters in the
page's URL. Assuming no query string or fragment identifier, that should
be "tml" for a file with a ".html" suffix.
return pagenumber - 0;

Subtracting zero form the string "tml" will force a type conversion of
the string to a number prior to the subtraction. "tml" is no a number so
the result will be NaN, and all subsequent mathematical operations
acting on NaN will themselves return NaN.
}

function goForward() {
var page = getpagenumber();
if (page < 100)

NaN is never less than 100.
parent.main.location.href = 'bg' + pad(page + 1,3) + '.html';
}
function goBackward() {
var page = getpagenumber();
if (page > 1)
<snip>

And NaN is never greater than 1.

Richard.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top