Wrox Programmer Forums
| 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
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???????:(

 
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

<><
 
Old June 28th, 2004, 04:41 PM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 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?
 
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

<><




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





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