SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Jun 2007
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    document.images.imageName is null or not an object

    When I run my code,

    document.images.imageName.src=this.h_image();


    I got the error message: “document.images.imageName is null or not an object”

    but using the alert(this.h_image()), there is ../img/image1.jpg in a alert box.

    Why can get this error?

  2. #2
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You should always use document.getElementById when referencing elements.

    Code:
    var el = document.getElementById('imageId');
    el.src = this.h_image();
    you will be getting this error because document.images or document.images.imageName does not exist.


  3. #3
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    doubla post sorry.


  4. #4
    SitePoint Member
    Join Date
    Jun 2007
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks.

    Yes, before I have once tried this way
    var MyImg= document.getElementById('imageName');
    MyImg.src = this.h_image();

    <img src="../../img/h_030.jpg" name="imageName" Id="imageName" width="470" height="334">

    but to get an error "MyImg is null or not an object".

    I have checked some books and internet, but still can't resolve it for more than one week.


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
  •