javascript textarea restriction problem
<p>I have a text area which i put a 250 character limit on for the user to type.  This works fine.  I added some code to edit that box on the fly.  Is it possible to structure the "edit' code to restrict the box so only 250 characters the same way as the initial add box??</p>

<p>Heres the box for adding:</p>

<p><strong>jsp</strong>:</p>

<pre><code>&lt;td colspan="3"&gt;
    You have &lt;strong&gt;&lt;span id="commentsCounter"&gt;${const['COMMENT_MAX_LENGTH']}&lt;/span&gt;&lt;/strong&gt; characters left.&lt;br/&gt;
    &lt;textarea id="comment" name="comment" rows="3"
        onfocus="characterCounter('commentsCounter',${const['COMMENT_MAX_LENGTH']}, this)"
        onkeydown="characterCounter('commentsCounter',${const['COMMENT_MAX_LENGTH']}, this)"
        onkeyup="characterCounter('commentsCounter',${const['COMMENT_MAX_LENGTH']}, this)"&gt;&lt;/textarea&gt;
        &lt;a href="javascript:addComment();"&gt;&lt;img src="../images/icon_add.gif" border="0" alt="Add"/&gt;&lt;/a&gt;
&lt;/td&gt;
</code></pre>

<p><strong>javascript</strong>:</p>

<pre><code>    function characterCounter(id, maxLen, inputElement)
{
    spanId = document.getElementById(id);

    if (spanId)
    {
        // Update the counter the user sees.
        var whatIsLeft = maxLen - inputElement.value.length;

        if ( whatIsLeft &lt; 0 ) whatIsLeft = 0;
        spanId.innerText = whatIsLeft;
    }

    // Restrict user from entering more than the maxlen.
    if ( inputElement.value.length &gt; maxLen )
    {
        inputElement.value = inputElement.value.substring( 0, maxLen );
    }
}
</code></pre>

<p><strong>Heres a snippet code for editing that box....how can I structure below to mirror the javascript above just to stop the box from entering more than 250 characters?</strong></p>

<pre><code>    function editCommentToggle( id )
{
    theRow = document.getElementById("id"+id);
    //user = theRow.cells[0].innerHTML;
    //date = theRow.cells[1].innerHTML;
    com = theRow.cells[2].innerHTML;


    idx = 2;


        // Comment field

        cell = theRow.cells[idx];
        while( cell.childNodes.length &gt; 0 ) cell.removeChild(cell.childNodes[0]);
        element = document.createElement("textarea");
        element.id="comments-"+id;
        element.rows="3";
        element.value = com;
        element.style.width =  "400px";
        element.maxLength="250";
        cell.appendChild(element);
</code></pre>

<p><strong>JUST ADDED:</strong></p>

<pre><code>maxlength = 250;
element.onfocus = element.onkeydown = element.onkeyup = function(){return characterCounterEdit(undefined, maxlength, element);}; 
        cell.appendChild(element);

 function characterCounterEdit(id, maxLen, inputElement)
{
    spanId = document.getElementById(id);

    if (spanId)
    {
        // Update the counter the user sees.
        var whatIsLeft = maxLen - inputElement.value.length;

        if ( whatIsLeft &lt; 0 ) whatIsLeft = 0;
        spanId.innerText = whatIsLeft;
    }

    // Restrict user from entering more than the maxlen.
    if ( inputElement.value.length &gt; maxLen )
    {
        inputElement.value = inputElement.value.substring( 0, maxLen );
    }
}
</code></pre>

<p>now Im getting:</p>

<p>'value.length' is null or not an object</p>
