2 Replies - 5272 Views - Last Post: 06 December 2011 - 03:58 PM

#1 guyfromri  Icon User is offline

  • D.I.C Addict

Reputation: 46
  • View blog
  • Posts: 817
  • Joined: 16-September 09

Uncaught Type Error: Cannot read property innerHTML of Null

Posted 06 December 2011 - 03:20 PM

hey guys!!!

So, I'm trying to set an Ajax script that will call my php, insert to db and echo the post back to the div. This was working before but it was at the bottom of the page...to fix that I added a new post container so I could make the inputbox populate the top and the post populate the bottom...the inputbox piece works great and the post does go in to the db and show if I refresh the page but does not populate after hitting the reply button....I debugged in Chrome and get error; Uncaught Type Error: Cannot read property innerHTML of Null....i'm stumpped


html output
<div class='loop_con_main' id='post_main_0'><div class='loop_container' id='post_0'>



Javascript
  function create_post_reply(post_id, db_id){
    if(!document.getElementById("post_rep_box_" + post_id.id).value)
      return false;   
    
    var str = document.getElementById("post_rep_box_" + post_id.id).value;
    
    var child  = document.getElementById("post_rep_form_" + post_id.id);
    var parent = document.getElementById(post_id.id);
    parent.removeChild(child);
  
    if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
      }
    else
      {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    xmlhttp.onreadystatechange=function()
      {
      if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
        document.getElementById("post_mn_" + post_id.id).innerHTML += xmlhttp.responseText;
        }
      }
    xmlhttp.open("GET","scripts/posts/create_post_reply.php?post=" + str + "&post_id=" + db_id, true);  
    xmlhttp.send();
  }



The line specifically getting the error is
document.getElementById("post_mn_" + post_id.id).innerHTML += xmlhttp.responseText;



As always, thanks in advance!!

Is This A Good Question/Topic? 0
  • +

Replies To: Uncaught Type Error: Cannot read property innerHTML of Null

#2 e_i_pi  Icon User is offline

  • = -1
  • member icon

Reputation: 795
  • View blog
  • Posts: 1,681
  • Joined: 30-January 09

Re: Uncaught Type Error: Cannot read property innerHTML of Null

Posted 06 December 2011 - 03:31 PM

Looks like it can't find the following element:
document.getElementById("post_mn_" + post_id.id)


What does your HTML DOM look like? Have you tried alerting post_id.id to see what value you get?
Was This Post Helpful? 1
  • +
  • -

#3 guyfromri  Icon User is offline

  • D.I.C Addict

Reputation: 46
  • View blog
  • Posts: 817
  • Joined: 16-September 09

Re: Uncaught Type Error: Cannot read property innerHTML of Null

Posted 06 December 2011 - 03:58 PM

lol...you know the cocky side of me didn't think it was necessary because I had it working previously but apparently I added a piece the PHP side that was throwing the way it came back...


Thanks for the input -- :) -- I believe it's now time for me to sleep before I do this a third time lol

BTW: I'm gonna aim for your name in the secret santa hat ;)

This post has been edited by guyfromri: 06 December 2011 - 03:59 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1