title: Auto-save textarea every so many seconds
body: <p>I need help with "auto-saving" a textarea. Basically, whenever a user is typing in the textarea, I would like to save a "draft" in our database. So for example, a user is typing a blog post. Every 15 seconds I would like for the script to update the database with all text input that was typed into the textarea.</p>
  
  <p>I would like for this to be accomplished thru jQuery/Ajax but I cannot seem to finding anything that is meeting my needs.</p>
  
  <p>Any help on this matter is greatly appreciated!</p>
  
  <p>UPDATE:</p>
  
  <p>Here is my PHP code:</p>
  
  <pre><code>&lt;?php
  
  $q=$_GET["q"];
  $answer=$_GET["a"];
  
  //Connect to the database
  require_once('mysql_connect.php') ;
  
  $sql="UPDATE english_backup SET q".$q."='".$answer."' WHERE student_id = {$_COOKIE['student']} LIMIT 1";
  $result = mysqli_query($dbc, $sql);
  </code></pre>
  
  <p>?></p>
  
  <p>Here is my javascript code:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  function showUser(str, answer)
  {
  if (str=="")
    {
    document.getElementById("txtHint").innerHTML="";
    return;
    } 
  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 &amp;&amp; xmlhttp.status==200)
      {
      document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
      }
    }
  xmlhttp.open("GET","getuser_english.php?q="+str+"&amp;a="+answer,true);
  xmlhttp.send();
  }
  &lt;/script&gt;
  </code></pre>