Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8247331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:48:45+00:00 2026-06-07T22:48:45+00:00

I have a <td> which I am turning into a textArea once I click

  • 0

I have a <td> 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 in the textarea. I want to trigger the character counter function soon as I jump into the editCommentToggle().

JavaScript:

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 > 0 ) cell.removeChild(cell.childNodes[0]);

        spanTag = document.createElement("span"); 
        spanTag.innerHTML = "You have <strong><span id='commentsCounter'>"+maxlength+"</span></strong> characters left.<br/>"; 
        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);    <%-- Run after HTC code --%>
                });

    // Actions field
    cell = theRow.cells[++idx];
    while( cell.childNodes.length > 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 < 0 ) whatIsLeft = 0;
        spanId.innerText = whatIsLeft;
    }

    // Restrict user from entering more than the maxlen.
    if ( inputElement.value.length > maxLen )
    {
        inputElement.value = inputElement.value.substring( 0, maxLen );
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T22:48:47+00:00Added an answer on June 7, 2026 at 10:48 pm

    Why not just call the required method inside the editCommentToggle(). You seem to suggest this is what you want to do, but im not really sure why you haven’t done it?

    function editCommentToggle( id )
    {
       //code to get the element here first as pointed out by a comment below.
    
       characterCounterEdit('commentsCounter', maxlength, element);
    
       .... rest of the function
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an API which I am turning into an internal DSL. As such,
I have a .NET Windows serivce protected with {smartassembly} which works fine, except that
I am integrating videos into a website we have which I have never done
I have button which post values of form to url but during post i
I was wondering which is a better/faster/more efficient way of turning arbitrary strings into
I have an excel spreadsheet i am going to be turning into a DB
I have a series of editable lists which, on a press of a button
There are two problems I ran into last night which I have resolved now,
Is there any good practice (pattern) in turning asynchronous calls into synchronous? I have
Consider the apps that large blogs have (which work pretty much like an RSS

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.