SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,747
    Mentioned
    64 Post(s)
    Tagged
    0 Thread(s)

    'has no properties'

    I'm stumped. This line is causing an error (reported by FF, but the script fails in IE too):
    Error: document.getElementById("dis_hworld") has no properties
    Line: 44

    Code:
     document.getElementById('dis_hworld').value = myrace.hworld;
    This is called within a function (which is called correctly). myrace.hworld is a valid string. (checked by Alerting before this line).

    The associated HTML tag:
    Code:
    <input type='text' class='shadow' name='dis_hworld' id='dis_hworld' value='' readonly>
    note: I have tried removing the value = and readonly attribs, but it has no effect.

    What am i missing?

  2. #2
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,747
    Mentioned
    64 Post(s)
    Tagged
    0 Thread(s)
    Never mind...
    Note to self: You can only call the function later in the code than the HTML tag :P

  3. #3
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To ensure that the entire page has finished loading before calling functions like this make use of the onload event (put your code in there and not in floating <script> blocks).

  4. #4
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,747
    Mentioned
    64 Post(s)
    Tagged
    0 Thread(s)
    Okay, i'm back

    Apparantly, the 'has no properties' bug follows me around.

    Now my problems center around a <select> box...

    Code:
    var onew = document.createElement('OPTION')
     onew.text = '-1';
    var hnum = document.getElementById('haircolor').length;
     for (var i = 0; i < (6 - hnum); i++) {
       document.getElementById('haircolor').add(onew,null);
     }
    for (var i = 0; i < 6; i++) {
       if (hair[racenum][i] != '') {
         document.getElementById('haircolor').options[i].value = i;
         document.getElementById('haircolor').options[i].text = hair[racenum][i];
       }
       else {
         document.getElementById('haircolor').options[i].text = '-1';
       }
     }
     var hcount = 0;
     for (var i = 0; i < 6; i++) {
      if (document.getElementById('haircolor').options[hcount].text == '-1') {
         document.getElementById('haircolor').remove(hcount);
         hcount--;
       }
       hcount++;
     }
    This code works in three stages: 'Fill' the select box so that it has 6 options. Replace 'filler' elements with values from an array. Remove 'excess' elements.

    The data currently in the arrays fills this way:
    hair[1] = '','','','','',''
    hair[2] = 'Black','Blond','Grey','','',''

    What i can tell is happening (via alerting):
    Pageloads, calls function (passing racenum = 1)
    0 New Element objects are created (the HTML tag is pre-loaded with 6 elements to prevent problems)
    Each element of hair[1] is parsed, and the Text of each Option is changed to -1.
    Each option is removed from the box; At this point, the box should be empty.
    A trigger calls the function again (passing racenum = 2)
    6 New Elements are created.
    The script begins to parse hair[2].
    Loop i = 0 executes correctly.
    Loop i = 1 crashes; 'haircolor has no properties'. The select box contains only 1 item (Black).


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
  •