beginners question on arrays

E

ef

Hi,

I'm breaking my head about something, it's probably simple.

I have the following peace of code:

=======

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<LINK TYPE="text/css" HREF="/f.css" REL="stylesheet">
<meta http-equiv="Content-Type" content="text/css; charset=iso-8859-1">
<title>f</title>

<script language="JavaScript">
<!--

function SymError()
{
return true;
}

window.onerror = SymError;

var SymRealWinOpen = window.open;

function SymWinOpen(url, name, attributes)
{
return (new Object());
}

window.open = SymWinOpen;

//-->
</script>

<script type="text/javascript" language="JavaScript" src="/java/menux.js">
</script>


</head>
<body onLoad="showMenu(1390)" onResize="if (isNS4) nsResizeHandler()">


<script language="JavaScript">
var menuitems = new Array();
menuitems[0] = new Array( 0, 0, 'm', false, '', 110, 109, 17 );
menuitems[1] = new Array( 0, 1, 'i', ' Home', 40, 22, 0);
menuitems[2] = new Array( 0, 2, 'i', ' Input', '#', '', 50, 22, 1);
menuitems[3] = new Array( 0, 3, 'i', ' Logout', '#', '', 50, 22, 2);
</script>

.......

</body>
===============

can i access the menuitems array from the /java/menux.js script, and how
should that be coded?

thanks in advance for your patience.

ef
 
R

RobG

ef said:
Hi,

I'm breaking my head about something, it's probably simple.

I have the following peace of code:

Peace to you too. :)
=======

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<LINK TYPE="text/css" HREF="/f.css" REL="stylesheet">
<meta http-equiv="Content-Type" content="text/css; charset=iso-8859-1">
<title>f</title>

<script language="JavaScript">

Language is depreciated, type is required.


No need to hide script content.
function SymError()
{ [...]


<script type="text/javascript" language="JavaScript" src="/java/menux.js">
</script>

Ditch the language attribute. Your issue (if there is one) may be in
menux.js.
</head>
<body onLoad="showMenu(1390)" onResize="if (isNS4) nsResizeHandler()">


<script language="JavaScript">

Insert language/type message here...
var menuitems = new Array();
menuitems[0] = new Array( 0, 0, 'm', false, '', 110, 109, 17 );
menuitems[1] = new Array( 0, 1, 'i', ' Home', 40, 22, 0);
menuitems[2] = new Array( 0, 2, 'i', ' Input', '#', '', 50, 22, 1);
menuitems[3] = new Array( 0, 3, 'i', ' Logout', '#', '', 50, 22, 2);
</script>

Below is a simpler (fewer characters) version of this declaration.
Why not put it in the head and reduce clutter in the body?
......

</body>
===============

can i access the menuitems array from the /java/menux.js script, and how
should that be coded?

Yes. Scripts are loaded and used as if they were coded in the page.
They are loaded asynchronously, so be careful what you call when, but
anything after page load /should/ be fine. See the example below.

To test if your issue is related to latency of the loaded JavaScript
file, run showMenu() from a button on the page. If it works OK from
there but not from body onload, it may be that your script hasn't
quite finished loading when onload tries to call functions within it.
thanks in advance for your patience.

ef

First is the HTML, below is the external JavaScript file.

/*** HTML ***/

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head>
<meta http-equiv="Content-Type"
content="text/css; charset=iso-8859-1">
<title>f</title>
<script type="text/javascript" src="tst.js"></script>
</head>
<body onLoad="sayA();">
<script language="JavaScript">
var menuitems = [];
menuitems[0] = [ 0, 0, 'm', false, '', 110, 109, 17 ];
menuitems[1] = [ 0, 1, 'i', ' Home', 40, 22, 0];
menuitems[2] = [ 0, 2, 'i', ' Input', '#', '', 50, 22, 1];
menuitems[3] = [ 0, 3, 'i', ' Logout', '#', '', 50, 22, 2];
</script>
<input type="button" value="Say array" onclick="sayA();">
</body></html>


/*** tst.js ***/

function sayA(){
var i=0, msg=[];
for ( word in menuitems ) {
msg.push(i++ + ' : ' + menuitems[word]);
}
alert(msg.join('\n'));
}
 
R

RobG

Stimp said:
what about people who use browsers that don't support javascript?

e.g. lynx

I can't speak specifically for Lynx, but I can say that any browser
that implements HTML 4[1] knows what a <script> element is and what
to do with it.

If the browser doesn't support JavaScript, it will ignore the
content.

1. Became a recommendation in November 1997 so any browser less than
say 8 years old should implement HTML 4.
 
T

Thomas 'PointedEars' Lahn

Stimp said:
what about people who use browsers that don't support javascript?

e.g. lynx

(We had this several before, you may want to use a search engine next time.)
As they are not borken HTML 3.2 compatible user agents, they have to ignore
the entire `script' element in that case (because it was introduced in that
version of HTML and previous versions are officially [by RFC] obsolete),
hardly displaying its content as you apparently suggest. On the other
hand, borken UAs should not be supported. So there is no need and really
no sense in commenting out `script' element content.


PointedEars
 

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,769
Messages
2,569,582
Members
45,062
Latest member
OrderKetozenseACV

Latest Threads

Top