beginners question on arrays

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ef

    #1

    beginners question on arrays

    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="JavaS cript">
    <!--

    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="JavaS cript" src="/java/menux.js">
    </script>


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


    <script language="JavaS cript">
    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
  • RobG

    #2
    Re: beginners question on arrays

    ef wrote:[color=blue]
    > Hi,
    >
    > I'm breaking my head about something, it's probably simple.
    >
    > I have the following peace of code:[/color]

    Peace to you too. :-)
    [color=blue]
    >
    > =======
    >
    > <!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="JavaS cript">[/color]

    Language is depreciated, type is required.

    <script type="text/javascript">
    [color=blue]
    > <!--[/color]

    No need to hide script content.
    [color=blue]
    >
    > function SymError()
    > {[/color]
    [...]
    [color=blue]
    >
    > <script type="text/javascript" language="JavaS cript" src="/java/menux.js">
    > </script>[/color]

    Ditch the language attribute. Your issue (if there is one) may be in
    menux.js.
    [color=blue]
    >
    >
    > </head>
    > <body onLoad="showMen u(1390)" onResize="if (isNS4) nsResizeHandler ()">
    >
    >
    > <script language="JavaS cript">[/color]

    Insert language/type message here...
    [color=blue]
    > 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>[/color]

    Below is a simpler (fewer characters) version of this declaration.
    Why not put it in the head and reduce clutter in the body?
    [color=blue]
    >
    > ......
    >
    > </body>
    > ===============
    >
    > can i access the menuitems array from the /java/menux.js script, and how
    > should that be coded?[/color]

    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.
    [color=blue]
    >
    > thanks in advance for your patience.
    >
    > ef[/color]

    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="JavaS cript">
    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'));
    }


    --
    Rob

    Comment

    • Stimp

      #3
      Re: beginners question on arrays

      On Wed, 4 May 2005 RobG <rgqld@iinet.ne t.auau> wrote:[color=blue]
      > ef wrote:
      >
      > <script type="text/javascript">
      >[color=green]
      >> <!--[/color]
      >
      > No need to hide script content.[/color]

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

      e.g. lynx
      --

      "I hear ma train a comin'
      .... hear freedom comin"

      Comment

      • RobG

        #4
        Re: beginners question on arrays

        Stimp wrote:[color=blue]
        > On Wed, 4 May 2005 RobG <rgqld@iinet.ne t.auau> wrote:
        >[color=green]
        >>ef wrote:
        >>
        >> <script type="text/javascript">
        >>[color=darkred]
        >>><!--[/color]
        >>
        >> No need to hide script content.[/color]
        >
        >
        > what about people who use browsers that don't support javascript?
        >
        > e.g. lynx[/color]

        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.


        --
        Rob

        Comment

        • Thomas 'PointedEars' Lahn

          #5
          Re: beginners question on arrays

          Stimp wrote:
          [color=blue]
          > On Wed, 4 May 2005 RobG <rgqld@iinet.ne t.auau> wrote:[color=green]
          >> ef wrote:
          >> <script type="text/javascript">
          >>[color=darkred]
          >>> <!--[/color]
          >>
          >> No need to hide script content.[/color]
          >
          > what about people who use browsers that don't support javascript?
          >
          > e.g. lynx[/color]

          (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

          Comment

          Working...