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 8235455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:49:03+00:00 2026-06-07T18:49:03+00:00

Ok, this might be an easy one, im just not sure how to do

  • 0

Ok, this might be an easy one, im just not sure how to do it. I have a main function where it’s taking in an “id”. This id is unique and I want to pass it over to another function that is doing a count for me and returns that count to an innerHtml span tag.

Reason for this is because I can have 5 of these open at the same time, but they will have the same span id name “editCommentsCounter”…I want them to be like “editCommentsCounter-id”

function editCommentToggle( id )
{
    theRow = document.getElementById("id"+id);
    //user = theRow.cells[0].innerHTML;
    //date = theRow.cells[1].innerHTML;
    com = theRow.cells[2].innerText ;
    comLength = theRow.cells[2].innerText.length ;

    idx = 2;
    maxlength = 250;
    count = maxlength - comLength;


        // 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='editCommentsCounter'>"+count+"</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('editCommentsCounter', maxlength, this);}; 
        cell.appendChild(element);

}

Basically I want to take :

   spanTag.innerHTML = "You have <strong><span id='editCommentsCounter'>"+count+"</span></strong> characters left.<br/>"; 

and make that into something like `span id=’editCommentsCounter-‘ + id

so when I call this:

element.onfocus = element.onkeydown = element.onkeyup = function(){return characterCounterEdit('editCommentsCounter', maxlength, this);};

I call this above with editCommentsCounter with that id attached to it

See what Im saying?

  • 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-07T18:49:05+00:00Added an answer on June 7, 2026 at 6:49 pm

    Use:

    document.getElementById("editCommentsCounter-" + id).innerHTML = someVal;
    

    You have a lot there but it seems like that is what you’re trying to do to write the innerHTML val. If not please tell me more in comments and I can suggest more.


    I see you want to dynamically build a new span, then populate the content. One thing that is puzzling in the beginning you reference the element and concat “id”+id. Have to think about this one so apologies for too quick response; was just looking at your end result.

    Setting the unique ID:

    var spanTag = document.createElement("span");
    spanTag.id = 'editCommentsCounter-' + id;
    spanTag.innerHTML = 'You have ...' + count + '...';
    document.body.appendChild(spanTag);
    

    I hope this helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This might be an easy one, but I'm not really experienced with sql. I
Ok, this might be an easy one, but I just can't get it. I
I know this might be very easy to some,, I have a simple string
I'm sure there's an easy answer here and i'm just over-complicating things, but i
Not sure exactly how to explain this but Imaging you have a table with
this is might be a very basic question, but seems like it's not easy
I know this might sound easy. I thought about using the first dot(.) which
This might be ridiculously easy for you but I've been struggling with this for
This might seem an easy question for some, but I am struggling with it.
I'm pretty new to Visual Studio so this might be an easy issue :)

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.