title: detect whether a text area is being used with javascript
body: <p>MAJOR THANKS TO EVERYONE WHO POSTED TO TRY TO HELP. YOU GUYS ARE AWESOME! :)</p>
  
  <p>I used @jsfriend00 solution and it accomplished the functionality I needed for client browser cache problem.</p>
  
  <p>Hi I have a question regarding javascript:</p>
  
  <p>Wondering if there is a way to detect whether a textarea is being used by a user meaning the user is messaging another user but there isn't yet an enter keystroke? </p>
  
  <p>I've been thinking I can solve my cache issue with my private networking stream if I can get the client browser cache to refresh only if the user is not attempting to message another user because then obviously they loose what they're typing because of automatic refresh.</p>
  
  <p>Say for example the following textarea:</p>
  
  <pre><code> &lt;html&gt;
   &lt;title&gt;&lt;/title&gt;
   &lt;head&gt;
   &lt;script&gt;
   function autoRefresh(refreshPeriod) {
   var obj = document.getElementById("create"); 
  
       function refreshIfSafe() {
       if (document.activeElement !== obj) { 
          window.location.reload();
        } else {
          setTimeout(refreshIfSafe, refreshPeriod);
        }
     }
         setTimeout(refreshIfSafe, refreshPeriod);
   }
  
         autoRefresh(2 * 1000);
  
    &lt;/script&gt;
  
    &lt;?php echo smiley_js(); ?&gt;
  
   &lt;/head&gt;
   &lt;body&gt;
  
  
  &lt;?php echo form_open('controller/function') ?&gt;
  &lt;p&gt;&lt;label for="create"&gt;chat here:&lt;span class="optional"&gt;&lt;/span&gt;&lt;/label&gt;                                
  &lt;textarea name="create" id="create" onfocus="autoRefresh(this.id)" rows="3" cols="20"&gt;&lt;/textarea&gt; 
  &lt;?php echo form_error('create'); ?&gt;
  &lt;/p&gt;
  &lt;?php echo form_submit('submit','chat');?&gt;
   &lt;?php echo form_close();?&gt;
   &lt;/body&gt;
   &lt;/html&gt;
  </code></pre>