Need javascript function to run after event
<p>I have a <code>&lt;td&gt;</code> which I am turning into a textArea once I click on a button.  This works fine.  I also have a characterCounterEdit function which also works.  The only thing is the character counter only  works when I click the cursor into the textarea.  I want it to trigger the character counter function soon as I jump into the editCommentToggle().  </p>

<p>Javacript:</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].innerText ;


    idx = 2;
    maxlength = 250;

        // Comment field
        cell = theRow.cells[idx];
        while( cell.childNodes.length &gt; 0 ) cell.removeChild(cell.childNodes[0]);

        spanTag = document.createElement("span"); 
        spanTag.innerHTML = "You have &lt;strong&gt;&lt;span id='commentsCounter'&gt;"+maxlength+"&lt;/span&gt;&lt;/strong&gt; characters left.&lt;br/&gt;"; 
        cell.appendChild(spanTag);
        element = document.createElement("textarea");
        element.id="commentsTextArea-"+id;
        element.rows="3";
        element.value = com;
        element.style.width = "400px";
        element.maxLength = "250";
        element.onfocus = element.onkeydown = element.onkeyup = function(){return characterCounterEdit('commentsCounter', maxlength, this);}; 
        cell.appendChild(element);

        $(function()
                {
                    setTimeout("syncCommentTableSizes()",0);    &lt;%-- Run after HTC code --%&gt;
                });

    // Actions field
    cell = theRow.cells[++idx];
    while( cell.childNodes.length &gt; 0 ) cell.removeChild(cell.childNodes[0]);

    link = document.createElement("a");
    link.href = 'javascript:saveComment('+id+')';

    element = document.createElement( "img" );
    element.className = "smallicon edit"; // check if we need this changed
    element.src="../images/icon_save.gif";
    element.border="0";
    element.alt = "Save";

    link.appendChild( element );

    cell.appendChild(link);
    cell.appendChild( document.createTextNode("  ") );

    link = document.createElement("a");
    link.href = 'javascript:cancelCommentEdit('+id+')';

    element = document.createElement( "img" );
    element.className = "smallicon delete"; // check if we need this changed
    element.src="../images/icon_cancel.gif";
    element.border="0";
    element.alt = "Cancel";

    link.appendChild(element);
    cell.appendChild(link);
}



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>
