SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jul 2007
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Simply JavaScript

    Thank you for your help. I'm working through the SitePoint book Simply JavaScript but am stuck on pages 68-69. My code does not work. I just get object required before the alert? I could post the code if I knew how but if you have access to the book or the free download pages you may be able to see what I mean.

    Regards
    Steve

  2. #2
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Steve,

    As explained in Chapter 7, an "object required" error means that you're attempting to access a property or method on a variable that contains a null value, rather than a valid object.

    In this case, the line that it's failing on is this alert:
    Code:
    alert(target.nodeName);
    So the error is being caused by the fact that the variable target has a value of null. Since that variable got its value from the getElementById call on the previous line, it means that the document did not contain an element with ID "berenger" when the script was being executed.

    Chances are you've linked to the script from the top of your HTML file, and you have failed to use the script structure shown on p.59 to make sure that your code is only executed after the document has fully loaded.
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference

  3. #3
    SitePoint Member
    Join Date
    Jul 2007
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Kevin

    Thanks for your reply - it works now I've placed the code below as you explained

    I'm sure I will make progress now. Your book is ideal for the course I've just taken - I will suggest it as recommended reading.

    Regards

    Steve


Bookmarks

Posting Permissions

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