Error: 'document.getElementById(...)' is null or not an object.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ananjy
    New Member
    • Mar 2008
    • 3

    Error: 'document.getElementById(...)' is null or not an object.

    Hi
    when i m trying to execute my ajax code using a link to display datas from another page named second.php.,
    i got an error when the page loads in "ie"., which runs perfectly in firefox.,

    here is my code

    Code:
    <script type="text/javascript">
    var i;
    function httprequest(i)
    {
    
    var xmlhttp;
    try
    {
     xmlhttp=new XMLHttpRequest();
    }
    catch(e)
    {
      try
      {
      xmlhttp=new Activexobject("Msxml2.XMLHTTP");
      }
      catch(e)
      { 
        try
    	{
        xmlhttp=new Activexobject("MICROSOFT.XMLHTTP")
    	}
    	catch(e)
    	{
    	 alert("ur browser doesnot support Ajax");
    	 return false;
    	}
      }
      
    }
    xmlhttp.onreadystatechange=function()
    { 
     if(xmlhttp.readyState==4)
     { 
       
       obj = document.getElementById( "idname" );
       
       obj.innerHTML = xmlhttp.responseText;
       getBufferText();
       
     }
    }
    
    xmlhttp.open("GET", "second.php?i="+i,true);
    xmlhttp.send(null);
    }
    
    function call_sec(i)
    {
     httprequest(i)
    }
    </script>
    [code=php]
    <table id="idname">

    .............
    first page contents
    ............... ..

    <a onclick="call_s ec(<? echo $i;?>)">second</a></table>
    [/code]



    when the page loads i get an error "Error: 'document.getEl ementById(...)' is null or not an object"
    but works well with firefox.,

    could anyone help me.,
    its very urgent.,

    thanks
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5388

    #2
    you have a typo - use:

    [CODE=javascript]new ActiveXObject
    [/CODE]
    in your IE section for creating the request-object.

    kind regards

    Comment

    • vjayis
      New Member
      • Mar 2008
      • 134

      #3
      Originally posted by gits
      you have a typo - use:

      [CODE=javascript]new ActiveXObject
      [/CODE]
      in your IE section for creating the request-object.

      kind regards

      Hi

      tried doing with the changes above., but still didnt get rid of the problem.,

      thanks

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5388

        #4
        please try to use a div instead of a table first ...

        kind regards

        Comment

        • vjayis
          New Member
          • Mar 2008
          • 134

          #5
          Originally posted by gits
          please try to use a div instead of a table first ...

          kind regards
          Hi

          tried changing to <div > tag., but not yet got the solution., when the page loads., i get the same error.,

          thanks

          Comment

          • gits
            Recognized Expert Moderator Expert
            • May 2007
            • 5388

            #6
            when the page loads? the XMLHttpRequest should be triggered by the buttonclick ... isn't it? what code is executed onload of the page?

            kind regards

            Comment

            • ananjy
              New Member
              • Mar 2008
              • 3

              #7
              Originally posted by gits
              when the page loads? the XMLHttpRequest should be triggered by the buttonclick ... isn't it? what code is executed onload of the page?

              kind regards

              Hi

              No code is executed on onload of the page.,
              The only script on my page is the javascript used for ajax.

              I hav enabled script debugging in browser setting., and get tht error which displays in the aert 'document.getEl ementById('...' ') is null or not an object.,

              if i disable the script debugging
              the page gets loaded well., and displays the result in the status bar as
              "done, but with some errors on the page".,

              here is my code again

              Code:
              <script type="text/javascript">
              var id;
              var action;
              
              
              function ajaxFunction(id,action)
              {
              
              var xmlHttp;
              try
                {
                // Firefox, Opera 8.0+, Safari
                xmlHttp=new XMLHttpRequest();
                }
              catch (e)
                {
                // Internet Explorer
                try
                  {
                  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
                  }
                catch (e)
                  {
                  try
                    {
                    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
                    }
                  catch (e)
                    {
                    alert("Your browser does not support AJAX!");
                    return false;
                    }
                  }
                }
              
              xmlHttp.onreadystatechange=function()
              { 
               if(xmlHttp.readyState==4)
               { 
               
                 document.getElementById("ajax").innerHTML=xmlHttp.responseText;
               }
              }
              
              xmlHttp.open("GET","ajax.php?id="+id+"&action="+action,true);
              xmlHttp.send(null);
              
              }
              
              function hidden(id,action)
              {
               ajaxFunction(id,action)
              }
              
              </script>

              kind regards
              vijay

              Comment

              • gits
                Recognized Expert Moderator Expert
                • May 2007
                • 5388

                #8
                the only part i could see where the error could come from is here:

                [CODE=javascript]document.getEle mentById("ajax" )[/CODE]
                do you have a node with id = 'ajax' in your document? ...

                kind regards

                Comment

                • ananjy
                  New Member
                  • Mar 2008
                  • 3

                  #9
                  Originally posted by gits
                  the only part i could see where the error could come from is here:

                  [CODE=javascript]document.getEle mentById("ajax" )[/CODE]
                  do you have a node with id = 'ajax' in your document? ...

                  kind regards



                  Hi got solution for the error,
                  i just simply added an if condition before tht line and got the solution.,
                  and thanks for tht.,

                  but after the page gets loaded.,
                  it displays the message in status bar as.,
                  "Done, but with some errors on page."

                  what might be the error???

                  how can i get an solution for this.,

                  regards

                  Comment

                  Working...