Can you help me understand this javascript example that runs on IE and Opera and crashes under Mozil

J

Jerry Asher

The page and javascript below will render correctly on IE and Opera,
but fails under Mozilla. Under IE and Opera, it prints out two
tables. Under Mozilla, only one table. Venkman says it dies at this
line:

outputArray( "Array n2 contains", n2 );


Error ``outputArray is not defined'' [xs] in file
``http://www.theashergroup.com/junk/InitArray.html'', line 30,
character 0.
Stopped for error handler.
#0: function initializeArrays() in
<http://www.theashergroup.com/junk/InitArray.html> line 30
028:
029: outputArray( "Array n1 contains", n1 );
030: outputArray( "Array n2 contains", n2 );
031: }
032:


A copy of this page is at
http://www.theashergroup.com/junk/InitArray.html

Questions:

A) What is wrong with that example and page?
B) Where is the best place to ask similar questions?
C) How do I set a breakpoint or a "future breakpoint" at line 29?
D) How do I step through this using Venkman? I can't figure
out how to start the script.

Thank you,

Jerry



<?xml version = "1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<!-- Fig. 11.3: InitArray.html -->
<!-- Initializing an Array -->

<html xmlns =" http://www.w3.org/1999/xhtml">
<head>
<title>Initializing an Array</title>

<script type =" text/javascript">
<!--
// this function is called when the <body> element's
// onload event occurs
function initializeArrays()
{
var n1 = new Array( 5 ); // allocate 5-element Array
var n2 = new Array(); // allocate empty Array

// assign values to each element of Array n1
for ( var i = 0; i < n1.length; ++i )
n1[ i ] = i;

// create and initialize five-elements in Array n2
for ( i = 0; i < 5; ++i )
n2[ i ] = i;

outputArray( "Array n1 contains", n1 );
outputArray( "Array n2 contains", n2 );
}

// output "header" followed by a two-column table
// containing subscripts and elements of "theArray"
function outputArray( header, theArray )
{
document.writeln( "<h2>" + header + "</h2>" );
document.writeln( "<table border = \"1\" width =" +
"\"100%\">" );

document.writeln( "<thead><th width = \"100\"" +
"align = \"left\">Subscript</th>" +
"<th align = \"left\">Value</th></thead><tbody>" );

for ( var i = 0; i < theArray.length; i++ )
document.writeln( "<tr><td>" + i + "</td><td>" +
theArray[ i ] + "</td></tr>" );

document.writeln( "</tbody></table>" );
}
// -->
</script>

</head><body onload =" initializeArrays()"></body>
</html>


<!--
**************************************************************************
* (C) Copyright 2002 by Deitel & Associates, Inc. and Prentice Hall.
*
* All Rights Reserved.
*
*
*
* DISCLAIMER: The authors and publisher of this book have used their
*
* best efforts in preparing the book. These efforts include the
*
* development, research, and testing of the theories and programs
*
* to determine their effectiveness. The authors and publisher make
*
* no warranty of any kind, expressed or implied, with regard to these
*
* programs or to the documentation contained in these books. The
authors *
* and publisher shall not be liable in any event for incidental or
*
* consequential damages in connection with, or arising out of, the
*
* furnishing, performance, or use of these programs.
*
**************************************************************************
-->
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top