'Object' is undefined

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

    'Object' is undefined

    Iam trying to make the devshed tutorial for JavaScrip Object lesson to
    work in my PC. The calendar.js file has the object 'Calendar'
    constructed but when I called using the below html doc, I get the
    "Calendar' is undefined error for line 6 and 7, where the obj1 and
    obj2 are specified.
    The full code of the calendar.js is in
    Founded in 1997, DEVShed is the perfect place for web developers to learn, share their work, and build upon the ideas of others.


    Both the files are in the same directory. Iam using Windows 2000
    Professional with IE6.

    Appreciate any help to resolve this problem.

    <html>
    <head>
    <script language="JavaS cript" src="calendar.j s"></script>
    </head>
    <body bgcolor="white" >
    <script> obj1 = new Calendar(2, 2005); </script>
    <script> obj2 = new Calendar(7, 2001); </script>
    </body>
    </html>


    TIA

    Sam
  • HikksNotAtHome

    #2
    Re: 'Object' is undefined

    In article <4d010e73.03100 91737.4ef949ac@ posting.google. com>, sams@freeddns.o rg
    (sams) writes:
    [color=blue]
    >Appreciate any help to resolve this problem.
    >
    >
    ><head>
    ><script language="JavaS cript" src="calendar.j s"></script>
    ></head>
    >
    ><script> obj1 = new Calendar(2, 2005); </script>
    ><script> obj2 = new Calendar(7, 2001); </script>[/color]

    Its a timing issue. You are trying to call the new Calendar() function before
    the calendar.js file has loaded to the point that it exists. Try using the
    onload to fire them off, and it should solve the undefined object errors.
    --
    Randy

    Comment

    • Lasse Reichstein Nielsen

      #3
      Re: 'Object' is undefined

      hikksnotathome@ aol.com (HikksNotAtHome ) writes:
      [color=blue]
      > Its a timing issue. You are trying to call the new Calendar() function before
      > the calendar.js file has loaded to the point that it exists. Try using the
      > onload to fire them off, and it should solve the undefined object errors.[/color]

      That is unlikely. The script is loaded and executed before parsing
      continues. Some browsers allow parsing to continue earlier by adding
      the defer attribute to the script tag, but it will still stop at the
      next non-defer script tag.

      A more likely problem is that "calendar.j s" is a verbatim copy of the
      script on the referred page ... including the <script> tag.

      In an external JS file, you must not have
      <script language="JavaS cript">
      at the beginning and </script> at the end. That will give syntax errors
      that will prevent the file from being executed.

      The page at devshed.com is slightly misguiding in that it gives the
      code with <script> tags around, but later gives code that uses it
      as an external file.

      /L
      --
      Lasse Reichstein Nielsen - lrn@hotpop.com
      Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
      'Faith without judgement merely degrades the spirit divine.'

      Comment

      • HikksNotAtHome

        #4
        Re: 'Object' is undefined

        In article <r81lu8nh.fsf@h otpop.com>, Lasse Reichstein Nielsen <lrn@hotpop.com >
        writes:
        [color=blue]
        >hikksnotathome @aol.com (HikksNotAtHome ) writes:
        >[color=green]
        >> Its a timing issue. You are trying to call the new Calendar() function[/color]
        >before[color=green]
        >> the calendar.js file has loaded to the point that it exists. Try using the
        >> onload to fire them off, and it should solve the undefined object errors.[/color]
        >
        >That is unlikely. The script is loaded and executed before parsing
        >continues. Some browsers allow parsing to continue earlier by adding
        >the defer attribute to the script tag, but it will still stop at the
        >next non-defer script tag.[/color]

        So if I load 100 .js files, then nothing will happen until all 100 of those
        files are loaded? Or am I understanding wrong?

        I know the onload event handler won't fire until the entire page is loaded, but
        I seem to recall having problems where I was trying to call functions that had
        not been downloaded from an external .js file in the past. Using the body's
        onload to call them solved my problems.

        Although, with regards to the OP, I didn't look at the .js file to see if it
        had the most common error - the script tags in it.
        --
        Randy

        Comment

        • Lasse Reichstein Nielsen

          #5
          Re: 'Object' is undefined

          hikksnotathome@ aol.com (HikksNotAtHome ) writes:
          [color=blue]
          > So if I load 100 .js files, then nothing will happen until all 100
          > of those files are loaded? Or am I understanding wrong?[/color]

          That is correct. You can check it with only one JS file where you do
          something boring like counting to a hundred million.

          <h1>Header</h1>
          <script type="text/javscript" src="longjs.js" ></script>
          <!-- script contains
          for (var i=0;i<100000000 ;i++) {var x=i;}
          -->
          <h1>Header</h1>
          [color=blue]
          > I know the onload event handler won't fire until the entire page is
          > loaded, but I seem to recall having problems where I was trying to
          > call functions that had not been downloaded from an external .js
          > file in the past. Using the body's onload to call them solved my
          > problems.[/color]

          If you could remember which browser you were using, it's worth
          testing.

          Waiting for the scripts to finish is actually necessary, since they
          can contain document.write' s, and even document.write' s writing new
          script tags that can define functions that the next script tag will
          need.
          [color=blue]
          > Although, with regards to the OP, I didn't look at the .js file to
          > see if it had the most common error - the script tags in it.[/color]

          It's a guess. He didn't show us his .js file, but from the description
          he seemed to be following, it is a likely mistake.

          /L
          --
          Lasse Reichstein Nielsen - lrn@hotpop.com
          Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
          'Faith without judgement merely degrades the spirit divine.'

          Comment

          • HikksNotAtHome

            #6
            Re: 'Object' is undefined

            In article <llrt5pxb.fsf@h otpop.com>, Lasse Reichstein Nielsen <lrn@hotpop.com >
            writes:
            [color=blue]
            >hikksnotathome @aol.com (HikksNotAtHome ) writes:
            >[color=green]
            >> So if I load 100 .js files, then nothing will happen until all 100
            >> of those files are loaded? Or am I understanding wrong?[/color]
            >
            >That is correct. You can check it with only one JS file where you do
            >something boring like counting to a hundred million.
            >[/color]

            It seems the one I used to test it was a simple array file that had 30k or so
            entries, and tried to process it before the page loaded and got errors (NS6 I
            think, but don't remember for sure). Since NS6 is basically old now, it may be
            something that got changed in NS7, or, I could be remembering the browser
            wrong.
            [color=blue][color=green]
            >> I know the onload event handler won't fire until the entire page is
            >> loaded, but I seem to recall having problems where I was trying to
            >> call functions that had not been downloaded from an external .js
            >> file in the past. Using the body's onload to call them solved my
            >> problems.[/color]
            >
            >If you could remember which browser you were using, it's worth
            >testing.[/color]

            I think it was NS6 but not absolutely positive. Its been about a year or so,
            and didn't really worry with it anymore, just moved it to the onload and went
            on as a happy camper :)
            [color=blue]
            >Waiting for the scripts to finish is actually necessary, since they
            >can contain document.write' s, and even document.write' s writing new
            >script tags that can define functions that the next script tag will
            >need.[/color]

            necessary or desirable? I can't see where the browser could know that it would
            be necessary to wait. If it could, it could be assumed that the browser should
            know to wait for the page to load before executing scripts, as it may need an
            element in the body that doesn't exist yet. But I can see the logic behind not
            executing more script until the last script loads though.
            [color=blue][color=green]
            >> Although, with regards to the OP, I didn't look at the .js file to
            >> see if it had the most common error - the script tags in it.[/color]
            >
            >It's a guess. He didn't show us his .js file, but from the description
            >he seemed to be following, it is a likely mistake.[/color]

            Isn't it just grand trying to debug code you can't see? <g>
            --
            Randy

            Comment

            • Richard Cornford

              #7
              Re: 'Object' is undefined

              "HikksNotAtHome " <hikksnotathome @aol.com> wrote in message
              news:2003101020 2113.15462.0000 3486@mb-m06.aol.com...[color=blue]
              > In article <llrt5pxb.fsf@h otpop.com>, Lasse Reichstein Nielsen[/color]
              <lrn@hotpop.com >
              <snip>[color=blue]
              >It seems the one I used to test it was a simple array file that
              >had 30k or so entries, and tried to process it before the page
              >loaded and got errors (NS6 I think, but don't remember for sure).
              >Since NS6 is basically old now, it may be something that got
              >changed in NS7, or, I could be remembering the browser wrong.[/color]
              <snip>

              I remember having timing problems with Netscape 6.2 loading a 90k array
              in a JS file, so I think you have the right browser.

              Richard.


              Comment

              • sams

                #8
                Re: 'Object' is undefined

                > In an external JS file, you must not have[color=blue]
                > <script language="JavaS cript">
                > at the beginning and </script> at the end. That will give syntax errors
                > that will prevent the file from being executed.[/color]

                Thank you, I removed the <Script></script> tags from the .js file and
                no other change. It worked. Great.

                Apprecite all your help.

                Sam

                Comment

                Working...