p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Javascript How-To (http://p2p.wrox.com/forumdisplay.php?f=87)
-   -   book code (http://p2p.wrox.com/showthread.php?t=14747)

skicrud June 28th, 2004 02:40 PM

book code
 
On page 242 of javascript edition 1 has the following code;
<html>
<head>

<script language=javascript>

var pagesVisited = new Array();

function returnPagesVisited()
{
    var returnValue = "So far you have visited the following pages\n";
    var pageVisitedIndex;
    var numberOfPagesVisited = pagesVisited.length;
    for(pageVisitedIndex = 0; pageVisitedIndex < numberOfPagesVisited; pageVisitedIndex++)
    {
    returnValue = returnValue + pagesVisited[pageVisitedIndex] + "\n";
    }

return returnValue;
}

function addPage(fileName)
{
var fileNameStart = fileName.lastIndexOf("/") + 1;
fileName = fileName.substr(fileNameStart);
pagesVisited[pagesVisited.length] = fileName;
return true;
}

</script>
</head>
<frameset cols=50%,*>
<frame name=fraLeft src="page_a.htm">
<frame name=fraRight src="page_b.htm">
</frameset>
</html>

the next page uses 4 copies of the following naming then page_a through page_d;

<html>
<head>

<script language=javascript>

var pagesVisited = new Array();

function returnPagesVisited()
{
    var returnValue = "So far you have visited the following pages\n";
    var pageVisitedIndex;
    var numberOfPagesVisited = pagesVisited.length;
    for(pageVisitedIndex = 0; pageVisitedIndex < numberOfPagesVisited; pageVisitedIndex++)
    {
    returnValue = returnValue + pagesVisited[pageVisitedIndex] + "\n";
    }

return returnValue;
}

function addPage(fileName)
{
var fileNameStart = fileName.lastIndexOf("/") + 1;
fileName = fileName.substr(fileNameStart);
pagesVisited[pagesVisited.length] = fileName;
return true;
}

</script>
</head>
<frameset cols=50%,*>
<frame name=fraLeft src="page_a.htm">
<frame name=fraRight src="page_b.htm">
</frameset>
</html>

when I run the code I keep getting object expected error.
Can anyone help me???????:([?]


Snib June 28th, 2004 04:24 PM

HUH!!?!

What on earth is the function lastIndexOf()?? I think you mean indexOf()....?

Hope this helps,

Snib

<><

Imar June 28th, 2004 04:41 PM

No no no, lastIndexOf does exist as well. lastIndexOf returns, unsurprisingly, the last index of a string occurence. It works pretty much the same as indexOf, but it starts searching at the end.

Search Google for lastIndexOf JavaScript to see what I mean....

Can you tell us where you get the error? That is, tell us the page and the line number. Makes it easier to spot any error....

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Thieves Like Us by New Order (Track 6 from the album: Substance - Disc 1) What's This?

Snib June 28th, 2004 05:11 PM

Ahh, thanks for clearing that up, Imar. I had never heard of it.

Snib

<><


All times are GMT -4. The time now is 10:46 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.