dcsimg
www.webdeveloper.com
Results 1 to 5 of 5

Thread: Script appears to be failing while instantiating a new object

  1. #1
    Join Date
    Feb 2014
    Posts
    6

    Arrow Script appears to be failing while instantiating a new object

    I have a very simple html page with java script embedded to create an object and display some properties of the object. But it appears to be failing when I instantiate the new object. I confirmed that by removing the line where I am instantiating it and re-running the page with some alert messages. If I remove the line starting with var log...., the alert("test") display fine, else it does not display

    <!DOCTYPE html>
    <head>
    <title>YouCube - The Blog for Cube Puzzlers</title>
    <script = "text/javascript">
    function Blog(body, date) {
    this.body = text;
    this.date = date;
    }

    var blog = [ new Blog("Got the new cube I ordered", "08/10/2012") ];
    alert("test");
    numEntries = blog.length;
    alert(numEntries);
    function showBlog(numEntries)
    {
    numEntries = blog.length;
    alert(numEntries);
    if (!numEntries)
    {
    numEntries = blog.length;
    alert(numEntries);
    }
    }
    </script>
    </head>
    <body>
    <h2>YouCube - The Blog for Cube Puzzlers</h2>
    <img src = "cube.png" alt = "YouCube" />
    <div id="blog"></div>
    <input type = "button" id = "showall" value = "Show all Blog Entries" onclick = "showBlog()" />
    </body>
    <?html>

    Any ideas/thoughts on what I could be doing wrong?

    Thanks

  2. #2
    Join Date
    Dec 2013
    Posts
    63
    Hi. In function 'Blog(...)' you have 'this.body = text'. 'text' is not defined! I think it should be 'this.body = body'

  3. #3
    Join Date
    Feb 2014
    Posts
    6
    Quote Originally Posted by blasphemy View Post
    Hi. In function 'Blog(...)' you have 'this.body = text'. 'text' is not defined! I think it should be 'this.body = body'
    Oh man...that was a bummer. I have been so focussing on the var blog instantiation, didn't go back and check carefully.

    Thanks much !!!

  4. #4
    Join Date
    Dec 2013
    Posts
    63
    Do you use 'JavaScript console'? In all modern browsers there are 'Tools for webmasters'. One of the most important part of it is 'Javascript console'. I copied your code and pasted into blank file on my computer. I opened it in my browser (with JS console opened) and I found the error very quickly.

  5. #5
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,519
    Can you please WRAP your code in forum tags, makes it easier to read for one. Your going to get help quicker as well.

    So without wading through that wall of text, I am going to have a stab in the dark here and say that you are either trying to access a property not yet available in the document body or an item that has not fully initalized, in both cases, use of window.onload would be a cure.
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles