Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 28th, 2004, 02:40 PM
Authorized User
 
Join Date: Sep 2003
Location: , , .
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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???????:(

Reply With Quote
  #2 (permalink)  
Old June 28th, 2004, 04:24 PM
Friend of Wrox
 
Join Date: Nov 2003
Location: , , .
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

HUH!!?!

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

Hope this helps,

Snib

<><
Reply With Quote
  #3 (permalink)  
Old June 28th, 2004, 04:41 PM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

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?
Reply With Quote
  #4 (permalink)  
Old June 28th, 2004, 05:11 PM
Friend of Wrox
 
Join Date: Nov 2003
Location: , , .
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

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

Snib

<><
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with code from book boro BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 2 March 12th, 2009 11:28 PM
C# Code for this book now available jminatel BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 0 April 10th, 2006 09:16 AM
Where is the code of this book! zjut C# 0 October 18th, 2004 10:08 PM
Where can you get the code for the book jjk8501 Classic ASP Databases 1 September 18th, 2003 07:07 AM



All times are GMT -4. The time now is 08:08 PM.


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