Javascript error: Error: ta is not defined
<p>I am new to JavaScript and I am trying to add a character counter to a text field using this code: </p>

<pre><code>$(function(){
  $('.txtclass').keypress(function(){
      ta = $(this);
      if(ta.val().length &gt;= 350){
          ta.val( ta.val().substr(0, 350) );
      } else {
          $("#counter span").text(350-ta.val().length);
      }
  });
});

setInterval('$("#counter span").text(350-ta.val().length);', 350);
</code></pre>

<p>I get that JavaScript error:  <code>"Error: ta is not defined"</code> and points me to that specific line in my code.</p>

<p>Any insight into whats happening and how to fix it would be really appreciated as I'd like to add more counters for other text-fields into the website elsewhere. </p>

<p>Edit: here's the html for the counter</p>

<pre><code> &lt;div id="counter"&gt;&lt;span&gt;350&lt;/span&gt; characters remaining.&lt;/div&gt;
    &lt;/div&gt;
</code></pre>
