Topic: Web

Beginning JavaScript (0764544055) cover image

Beginning JavaScript

Paul Wilton
ISBN: 978-0-7645-4405-7
Paperback
1010 pages
June 2000
View Most Recent Edition of This Title
This title is out-of-print and not currently available for purchase from this site.

Do you think you've discovered an error in this book? Please check the list of errata below to see if we've already addressed the error. If not, please submit the error via our Errata Form. We will attempt to verify your error; if you're right, we will post a correction below.

ChapterPageDetailsDatePrint Run
31 Typographical errors on page 31

In the fourth line of the third paragraph on the page, " " should read " ".

In the second to last paragraph, beneath the code, the copywrite symbol (©) is missing from the text.

21-Jan-02 1
38 "Tasks" wrongly spelt.

This reads - "On this browser you need to choose Tools from the Tasts menu, and select the JavaScript Console option."
It should Read - "On this browser you need to choose Tools from the Tasks menu, and select the JavaScript Console option."

21-Jan-02 1
45 Incorrect description of order of execution for a postfix increment

Thanks to Richard Waddell for pointing this out. At the bottom of the page, below the line of code

myVar = myNumber++ - 20;

the description should read "subtracts 20 from myNumber, assigns the result to myVar, and then increments myNumber by one"

This was corrected in the March 2001 reprint

05-Feb-01 1
85 Incorrect use of assignment operator

Thanks to Michael Smitheringale for pointing this one out. In the two code blocks at the bottom of the page, there is are lines of code that incorrectly use a single equals sign (the assignment operator) in a comparison, like this:

if (myAge=5)

They should have a double equals sign (the comparison operator), like this:

if (myAge==5)

This was corrected in the March 2001 reprint.

08-Feb-01 1
85 Incorrect semicolons in code blocks

Thanks to John Thorpe for spotting these. In the first example on page 85, there is a semi-colon mistakenly placed at the end of the line:

else if ( (myAge >= 30 & myAge <= 39) || (myAge >= 80 & myAge <= 89) );

In the second example, there is a missing semi-colon at the end of the line:

document.write("Your 5 years old")

There is also a missing semi-colon at the end of the same line in the third example.

23-Apr-01 1
87 colon in incorrect place gives incorrect syntax

Thanks to Bill Hooper for spotting this one.

Three lines above the bottom of the page, the book says "..starting below the case: Paul statement..". It should say "..starting below the case Paul: statement.."

17-Jul-01 1
87 Confusing text about switch statement

Thanks to Howard R. for pointing this out. At the bottom of the page, second line from the bottom, there's a sentence that ends "and would continue to the end of the switch statement". While this is true generally, in the example given it isn't the case because there are break statements in the code which would stop execution of the switch statement. So the end of the sentence should read "and would continue to the end of the switch statement, unless a break statement was encountered"

This was corrected in the March 2001 reprint

15-Feb-01 1
121 Missing quotes on tag attributes

Both the lt;scritpgt; tags in the code example have unquoted language attributes. Although many modern browsers will tollerate this, it isn't strictly legal syntax. It would be better if they both read:

&ltscript language="javascript">

(Note: the use of lowercase HTML is also preferable.)

21-Jan-02 1
121 Errors in

The HTML surrounding the code sections in this Try It Out are poorly marked up and do not coincide with the text that describes the example. The corrected code is as as follows:

<html>
<head>
 <script language="JavaScript" type="text/javascript">
 <!--
  function checkCharType(charToCheck){
   var returnValue = "O"
   var charCode = charToCheck.charCodeAt(0);
    if (charCode >= "A".charCodeAt(0) & charCode <= "Z".charCodeAt(0)){
     returnValue = "U";
    }else if (charCode >= "a".charCodeAt(0) & charCode <= "z".charCodeAt(0)){
     returnValue = "L";
    }else if (charCode >= "0".charCodeAt(0) & charCode <= "9".charCodeAt(0)){
     returnValue = "N";
    }
    return returnValue;
  }
 //-->
 </script>
</head>

<body>
 <script language="JavaScript" type="text/javascript">
 <!--
  var myString = prompt("Enter some text!", "Hello World!");
  switch (checkCharType(myString)){
   case "U":
    document.write("First character was upper case.");
    break;
   case "L":
    document.write("First character was lower case.");
    break;
   case "N":
    document.write("First character was a number.");
    break;
   default:
    document.write("First character was not a character or a number.");
  }
 //-->
 </script>
</body>
</html>

Our thanks to Raymond McNeill for this correction.

21-Jan-02 1
125 Message box should show 24, not 25

Thanks to Chuck Belna for pointing this one out. There are several instances on page 125 where we have said that the code will produce a message box containing the number 25. This is incorrect, it should produce a message box containing the number 24.

28-Mar-01 1
128 Backslash in code snippet gives an error

Thanks to Robert Pilic for spotting this one. At the bottom of the page, there is a code snippet demonstrating the substr() and lastIndexOf() methods. In the snippet, we've used:


fileName = fileName.substr(fileName.lastIndexOf("\") + 1);

This gives an error. It should read

fileName = fileName.substr(fileName.lastIndexOf("/") + 1);

This was corrected in the March 2001 reprint

23-Feb-01 1
140 Array object incorrectly named String object

Thanks to Clinton Hess for spotting this one. The paragraph starting "The final method for the String object.." should read "The final method for the Array object.."

28-Mar-01 1
143 Return values of getDay() method incorrect

Thanks to Victor Cosby for spotting this one. Under the heading "Getting Date Values", in the table we say that getDay() returns the day of the week as an integer, with Monday as 0. This is incorrect: Sunday is reurned as 0, Monday as 1, etc.

14-May-01 1
147 setMonth() method incorrectly identified as setDate()

Thanks to Chuck Belna for spotting this one. In the paragraph that starts "The same also applies to.." we've twice incorrectly used the setDate() method when we meant to use setMonth().

28-Mar-01 1
165 Variable is named myImage2, not myImage

Thanks to Chuck Belna for spotting this one. In the second paragraph, the variable is called myImage when it should, of course, be myImage2.

28-Mar-01 1
171 NAME attribute in IMG tag

Thanks to Laurence Scotford for spotting this one.

Both the IMG elements in the code have been given the same name. Since the name of the tag is not used to refer to IMG elements in this peice of code then the code works as expected. However, if the name had been used to identify the element to change then the code would not have worked correctly.

The first IMG tag should read:

<IMG NAME=img0 SRC="usa.gif" BORDER=0 >

15-Aug-01 1
174 incorrect case in code

references to "windows 95" and "windows 98"; in the getOS function should read "Windows 95" and "Windows 98" respectively, as in:

|| (navInfo.indexOf("Windows 95") != -1)
|| (navInfo.indexOf("Windows 98") != -1)

16-Aug-02 1
208 Misplaced quotes

Double quotes on the second and third INPUT radio buttons should be placed around the values of the NAME attributes and not around the attributes themselves - i.e.:

<TD><INPUT TYPE="radio" NAME="radCPUSpeed"
    onclick="return radCPUSpeed_onclick(1)" VALUE="1 GHz"></TD>
<TD>1 GHz</TD>
<TD><INPUT TYPE="radio" NAME="radCPUSpeed"
    onclick="return radCPUSpeed_onclick(2)" VALUE="1.5 GHz"></TD>
<TD>1.5 GHz</TD>

22-Jul-02 1
228 Missing Q

Thanks to Luciano Santucci for spotting this mistake. In between the two code blocks at the bottom of the page, we have a sentence that finishes "...and a button named buttonCheck". It should say "... and a button named buttonCheckQ"

17-Aug-01 1
231 Curly brace incorrect in code block

Thanks to Krista Murchek for alerting us to this one:

In the second code block, in the line following: questionHTML = questionHTML + " CHECKED"; there is an opening curly brace, {. It should be a closing curly brace, }.

24-Jul-01 1
240 Incorrect spelling of tag

Thanks to Troy D. Wallwork for spotting this one. At the bottom of the page <FRAMESET> is spelled incorrectly as <FRAMSET>

This was corrected in the March 2001 reprint

16-Feb-01 1
267 Discrepancy in Try It Out code

Thanks to Steve Wharton for letting us know aboout this error.

There's a discrepancy in the code in that the window_onunload() function in the Try It Out code on this page is different to that in the How It Works section on page 270. Both forms of code should work fine, but to be more compact, it is suggested that you use the function on page 270.

26-Nov-01 1
269 Variable is winLeft, not winleft

Thanks to Chuck Belna for spotting this. At the end of the second paragraph, a variable is incorrectly identified as winleft, when it should be winLeft.

28-Mar-01 1
273 Frame name spelled incorrectly

Thanks to Chuck Belna for alerting us to this one. In the second paragraph, we've spelled fraGlobalFunctions incorrectly as fraDlobalFunctions

28-Mar-01 1
292 "third comma" should read "second comma"

Thanks to Tyler Howard for spotting this one:

In the fourth paragraph, the second-to-last sentence reads:

"Finally in the third element it puts everthing from after the third comma to the end of the string."

There is no third comma, it should say:

"Finally in the third element it puts everthing from after the second comma to the end of the string. "

03-Aug-01 1
296 First code block incorrect

Thanks to Michael O'Sullivan for submitting this correction.

In the first code block on the page, the line should read: var myString = "The event will be in May, the 21st of June";

21-Nov-01 1
297 Example of match() method only returns one match

At the top of the page, we have said that the example code on the previous page will return an array with two elements. This is not true; because the match is not global it willl stop at the first match it makes. Therefore the array only contains one element. Thanks to Chong Pit Chin for spotting this mistake.

11-Sep-01 1
314 Group number incorrect

Thanks to John Thorpe for alering us to this one.

About halfway down the page, the nbook says "then $0 refers to the group..". It should say "then $1 refers to the group.."

28-Jun-01 1
336 GetTimezoneOffset() incorrectly captitalized in two places

Twice in the text on the middle of the page we have incorrectly written GetTimezoneOffset() as GetTimeZoneOffset(); the z shouldn't be capitalized.

03-Sep-01 1
427 Logical error in getCookieValue function

In the function first displayed on 426/427 and then used in the code block on pages 429/430 (saved as MainPage.htm) there is a logic error. The code deals with searching for substrings within the browser cookie string.

The following line of code is highlighted:

var cookieStartsAt = cookieValue.indexOf(" " + cookieName + "=");

The leading space in the search string is noted. "[It is there] so that we don't inadvertently find cookie names or values containing the name that we require."

Hence if the cookie string contained "xFoo .... Foo.... yFoo" we'd avoid matching on the Foo in 'xFoo' and instead match on ' Foo'.

This is all fine and dandy, but...

If the cookie string contained cookie names "xFoo=.... yFoo= ... barFoo= ... toFoo=....." the 1st search code would not match " Foo" in any of them.
However the code following matches the string and the equals sign while not looking for the leading space and negates the cleverness of the preceding code.

   if (cookieStartsAt == -1)
   {
    cookieStartsAt = cookieValue.indexOf(cookieName + "=");
   }

This would match the 'Foo=' in 'xFoo=' . (That is the logic error)

The 'if' code is only in there to catch the case where the cookie name (in this case 'Foo') is at the very beginning of the string so the code block could be written instead:

function getCookieValue(cookieName)
{
   var cookieValue = document.cookie;
   var cookieStartsAt = cookieValue.indexOf(" " + cookieName + "=");

   if (cookieStartsAt == -1)
   {
      cookieStartsAt = cookieValue.indexOf(cookieName + "=");

      if ( (cookieStartsAt != -1) && (cookieStartsAt != 0) )
      {
         cookieStartsAt = -1;
      }
   }

   if (cookieSTartsAt == -1)
   {
      cookieValue = null;
   }
   else
   {
      cookieStartsAt = cookieValue.indexOf("=", cookieStartsAt) + 1;
      var cookieEndsAt = cookieValue.indexOf(";", cookieStartsAt);
      if (cookieStartsAt == -1)
      {
         cookieEndsAt = unescape(cookieValue.substring(cookieStartsAt, cookieEndsAt));
      }
      cookieValue = unescape(cookieValue.substring(cookieStartsAt, cookieEndsAt5));
   }
   return cookieValue;
}

07-Oct-02 1
445 Color of text is green, not dark blue

Thanks to Chuck Belna for spotting this. In the code block halfway down the page, the text in the <P> tag says "Some dark blue verdana 12 point text", when it actually is green

28-Mar-01 1
449 Code block incorrect

Thanks to Chuck Belna for alerting us to this one. In second line of the code block at the bottom of the page, it should say "left: 50%; top: 50%" to position the <P> tag within the <DIV> tag

28-Mar-01 1
460 Missing semi colon

In the innerOuterHTML_IE.htm Try It Out there is a missing semicolon at the end of line 16. As it is the line reads

actOnTag.innerHTML = textarea1.value

where it should read

actOnTag.innerHTML = textarea1.value;

07-May-02 1
472 Extra parameter in code

Thanks to Jon Lee for alering us to this one.

On the last line in the code block at the bottom of the page, there is an extra parameter "4". This should not be there.

16-Aug-01 1
490 Missing tag

The <FORM> tag on page 490 needs a closing </FORM> tag just before the </BODY> tag.

13-Nov-02 4
574 Missing semi colon in code

In the function "document_onmouseover(e)" (continued from the previous page) the srcElement.style.backgroundColor = "darkblue" should be ended with a ";"

22-Aug-02 1
628 ComplexForm.asp should be ComplexForm.htm

Thanks to Tom Illgen for spotting this one.

Towards the bottom of the page, we say "Save this in the same directory as the ComplexForm.asp...". It should say "Save this in the same directory as ComplexForm.htm..."

19-Apr-01 1
645 Incorrect use of equivalence test (==)

Thanks to Steve Murphy for spotting this one.

In several places in the code examples on the page, the equivalence test (==) is incorrectly used in place of the assignment operator (=) when assigning a value to the variable shippingCost. For instance, where we have "shippingCost == 4.95;" it should read "shippingCost = 4.95;"

06-Aug-01 1
727 Incorrect use of comparison operator

Thanks to Neil Strange for spotting this typo.

Towards the bottom of the ASP code, we have "adoConnection == null;". It should use the assignment operator and say "adoConnection = null;" This mistake is repeated on page 731 in the explanation of the code.

11-Sep-01 1
732 Extraneous </FONT> tag

Thanks to Neil Strange for spotting this typo.

At the bottom of the page, there is an extraneous </FONT> tag that is not needed.

11-Sep-01 1
758 Incorrect statement about the use of curly braces with "else if"

Thanks to John Fisher for pointing out this one.

In the solution to Chapter 3, Question 1 we have incorrectly stated that you need to use curly braces for code blocks following an else if statement. In fact, you can use a single line of code following an else if without the curly braces, although this is poor programming practice.

11-Apr-01 1
760 Confusion over solution to Chapter 3, Question 4

There's been some queries about the solution to this question. The question wasn't phrased very well, but the code is supposed to work as it does. It collects input from the user in a loop (the times table values), and will only exit the loop if the user enters -1. It then writes all the times tables to the screen.

11-Apr-01 1
761 Code for solution of Chapter 4, Question 1 is wrong

Thanks to Richard Hunter for spotting this one.

In the code, we've incorrectly used the getDay() method to get the day of the month, this returns the day of the week. We should have used getDate().

11-Apr-01 1
763 Missing brace

Thanks to Charlie Men for spotting this one.

In the solution given on page 763, there is a missing brace in the for loop at the end of the fix function:
<samp>
for (; zerosRequired > 0; zerosRequired--)
{
fixNumber = fixNumber + "0";
} <===== missing brace!
return fixNumber;
</samp>

This was corrected in the March 2001 reprint.

12-Feb-01 1
763 Solution incorrect.

Thanks to Alan Duchan for supplying us with a fix to this problem.

There is a problem with the solution supplied in the book. If the user enters a number with no decimal part (such as 123), the code works incorrectly, due to the fact the variable fixNumber contains no decimal point. To fix this, you need to add the lines:
if (fixNumber.lastIndexOf(".") == -1)
{
fixNumber = fixNumber + ".";
}
between the lines where fixNumber and zerosRequired are set.

30-Jul-01 1
770 Extra "degCent = " in code

Thanks to Michael O'Sullivan for spotting this mistake. There is an extra "degCent =" in the 7th line of the code. While this doesn't actually make the code break, it is isn't necessary and should be removed.

07-Nov-01 1
774 Missing </TR> tag

Thanks go to Michael O'Sullivan for submitting this.

In the block of code at the top of the page, there is a missing </TR> tag between the </TD> and </TABLE> tags.

04-Oct-01 1
796 Incorrect arguments in setCookie function

In the code shown in the book, the arguments in the setCookie function are wrong, which stops the code working. The correct arguments are shown below:

setCookie("pageFirstVisited",pageFirstVisited,"","")

setCookie("pageViewCount",pageViewCount,"","")

in the order they appear in the code

11-Apr-01 1
796 Missing +1 in code

The point at which pageFirstVisited's month is set is miing a +1 and a closing bracket, as in:
/
pageFirstVisited.sertMonth(pageFirstVisited.getmonth() + );

16-Aug-02 1
898 Host property does not indicate IP address

Thanks to Michael O'Sullivan for spotting this one. The host property of the Link object does not indicate the hostname and IP address of the URL, just the hostname and port number.

17-Aug-01 1
899 host property does not indicate IP address

Thanks to Michael O'Sullivan for spotting this one. The host property of the Location object does not indicate the hostname and IP address of the URL, just the hostname and port number.

17-Aug-01 1
1015 Error in Index

The fifth letter of the typeof() entry should not be capitalized.

12-Aug-02 1