title: Refreshing only 1 DIV via PHP after submit form
body: <p>I have a comments board on my page, to which I load different topics according to the page the user is on with XMLHttpRequest in a changeTopic() function. I originally had this at the end of my submit form php:</p>
  
  <pre><code>header('Location: http://' . $_SERVER['HTTP_HOST'] . $_POST['page']);
  </code></pre>
  
  <p>The problem is that I don't want to refresh the whole page, only the DIV that contains the messages. I tried running the changeTopic() function by inserting it inside script tags with echo. For one, I couldn't get .$_GET['topic']. working inside echo even if I made a variable of it first, but also I tried running the function by hard inserting one of the possible values with the following results:</p>
  
  <p>1) While the messages section refreshed right, I lost the form as it's contained in the index.html while I only load the messages from an external gettopic.php with query string. </p>
  
  <p>2) I got a weird result where I lost an external file that was loaded into a completely different div altogether. This file changes the hash of the main page, which is checked with every refresh and the right file is loaded according the hash, so using the whole page refresh never resulted in this.</p>
  
  <p>// EDIT</p>
  
  <pre><code>function changeTopic(topic) {
          if (topic=="") {
              document.getElementById("messagelist").innerHTML="";
              return;
          }
          if (window.XMLHttpRequest) {
              xmlhttp=new XMLHttpRequest();
          }
          else {
              xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
          }
          xmlhttp.onreadystatechange=function() {
              if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200) {
                  document.getElementById("messagelist").innerHTML=xmlhttp.responseText;
              }
          }
          xmlhttp.open("POST", "gettopic.php?t="+topic,true);
          xmlhttp.send();
      }
  </code></pre>
  
  <p>The main application on my page is a SVG map which I've done with RaphaelJS. The user can load information pages into another div 'info' from this SVG map. The pages are loaded with a similar function which in addition changes the #hash and runs the changeTopic() as well to change the message board so people can have a conversation about each topic.</p>
  
  <p>The PHP form takes the normal filled info as well as the hidden 'pageid' which is set by the current page the user is browsing, and sends it to the database. The different messages are sorted by this pageid so the changeTopic() function only brings the right messages: gettopic.php?t=topic ('pageid').</p>
  
  <p>After submitting the form I'd like only the messagespart to refresh and the form to clear. At the moment it's either a whole page refresh (user looses their position on the SVG map) or partial refresh where I lose the form (get a blank spot instead) and that weird information-page missing.</p>