more problems with IE

Discussion in 'JavaScript' started by jred2002, Feb 29, 2008.

  1. #1
    I wrote some javascript that works perfect in firefox but of course not the case it IE - IE 7 actually

    IE gave me the error - null is null or not an abject

    at point beyond this line this line - var select = document.getElementById("make_options");

    if I comment out one line - the error goes to the next line

    It's whenever I do anything to the select variable

    I'm stuck - any help would be greatly appreciated

    Here is the whole function

     // transform the JSON results into a drop down menu
      var select = document.getElementById("make_options");
      select.disabled=false;           // enable the dropdown
      select.onchange=getModels;       
      select.options[select.selectedIndex].disabled=true; // disable the 'Loading...' option
      select.options[select.selectedIndex].text="Select Make";
      
      for (var i = 0; i < json.feed.entry.length; ++i) {
        var entry = json.feed.entry[i];
          
    
      //isPreloading = false;
    
      
        // find the make entry
        if (entry.title.$t == "make(text)") {
          makeList = entry['gm$attribute']['gm$value']
          for (var j=0; j<makeList.length; ++j) {
            var option = document.createElement("option");
            make = makeList[j].$t
            option.appendChild(document.createTextNode(make));
            select.appendChild(option);
          }
          break;
        }
      }
    Code (markup):

     
    jred2002, Feb 29, 2008 IP
  2. roy.laurie

    roy.laurie Peon

    Messages:
    51
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    IE7 isn't finding an element with an ID of "make_options", apparently.
     
    roy.laurie, Mar 1, 2008 IP
  3. lephron

    lephron Active Member

    Messages:
    204
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #3
    After a call to getElementById you should always check that you actually have a DOM element. eg:

    var select = document.getElementById(id);
    if(!select) // error handling here - throw an exception, popup an alert, or just return etc
     
    lephron, Mar 2, 2008 IP