SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist N9ne's Avatar
    Join Date
    Aug 2002
    Location
    UK
    Posts
    596
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Can't figure this out - variable has no properties

    Code JavaScript:
                        // ERRONEOUS FIELD HIGHLIGHTING
                        function please() {
                            <?=$jsArray?>
     
                            if (items)
                            {
                                for (var x = 0; x < items.length; x++)
                                {
                                    //window.alert(items[x]);
                                    var xxx = document.getElementById(items[x]);
                                    var xyz = xxx.parentNode;
                                    xyz.setAttribute('class', 'highlight');
                                }
                            }
                        }

    Everything seems to work fine, but I do get an error (I'm using FireBug in FireFox). The error is:

    'xxx has no properties'

    I don't know how to get rid of it or what it really means (I'm new to JS). I wonder if anyone can shed any light on this!

    NB. xyz's class IS being changed so there's no issue there.

  2. #2
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It means your items array – which presumably is output by that PHP(?) tag – contains some value that doesn't correspond to an existing id attribute on the page.

    Is the DOM fully loaded before you call this function?
    Birnam wood is come to Dunsinane

  3. #3
    SitePoint Evangelist N9ne's Avatar
    Join Date
    Aug 2002
    Location
    UK
    Posts
    596
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I call the function in the onload attribute of the <body> tag.

  4. #4
    SitePoint Evangelist N9ne's Avatar
    Join Date
    Aug 2002
    Location
    UK
    Posts
    596
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually, I checked about it not finding one particular element, and I realised that I had a <select ...> which had a NAME but not an ID. I didn't realise it needed the ID, so I've put that in and the error's gone... works perfectly now.

    Thanks very much!


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
  •