Script to limit the no. of characters in a textbox not working. Any Ideas?
<p>I have a script which is supposed to limit the no. of characters entered in a text box or textarea. I know I can do this using maxlength attribute. But I want to use JS implementation.</p>

<p>Below is the fiddle:</p>

<p><a href="http://jsfiddle.net/xTrKD/" rel="nofollow">http://jsfiddle.net/xTrKD/</a></p>

<p>CODE:</p>

<pre><code>$(function() {
function limitText(limitField, limitNum) 
    { 
        if (limitField.value.length &gt; limitNum)
            { 
                limitField.value = limitField.value.substring(0, limitNum);
                }
        }

})​
</code></pre>

<p>HTML:</p>

<pre><code>&lt;input type="text" id="sessionNo" name="sessionNum" onKeyUp="limitText(this,5);" /&gt;
</code></pre>
