Jquery limit text in input box
<p>I want to limit number of chars in input text field.</p>

<p>Code I'm using:</p>

<pre><code>function limitText(field, maxChar){
    if ($(field).val().length &gt; maxChar){
       $(field).val($(field).val().substr(0, maxChar));
    }
}
</code></pre>

<p>Event is onkeyup.
When I type some text in input field cursor stays on the end of text but focus is backed on start of the text so I can't see cursor.</p>

<p>What can be a problem.</p>

<p>Browser is FF, on IE and chrome it is working correctly</p>
