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

  • Home
  • SEARCH
  • 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 8307403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:31:04+00:00 2026-06-08T18:31:04+00:00

** Update ** Modified the code for Ricardo Lohmann’s suggestion with the additional modification

  • 0

** Update **

Modified the code for Ricardo Lohmann’s suggestion with the additional modification of using val() instead of text().

It is still not correct, but is a whole lot more consistent. Initially, it is off by 1 character, and is progressively off by an additional 1 character for every enter key pressed in the text area. I’m not sure yet whether the text area is returning for it yet, but it is not a CRLF.

I think that is the main problem. I will do some testing on carriage returns and line feeds being passed to the SMS processor, and hope that I can convert it after the fact.

Parsing through the textarea value and adding 1 character to the count for every “enter key” pressed will get the value I am after.

If anyone has ideas on how to get the textarea to use a full CRLF, I’m all ears.


I’m allowing managers to create SMS messages and need to show them how many characters are in use. So far the number of characters is off by 1 when I start and then becomes wildly inaccurate over time.

<textarea id="message_content"></textarea>
<div id="message_length"></div>

The message content is initially set with Javascript.

uri_decoded = 'Test Message\r\nTest Message';

Selecting all the text with select-all and throwing into a text editor like Notepad++ shows 26 characters, which is correct. 22 for characters, 2 for white space, and 2 for the CRLF.

The following code shows 25 characters initially, and then just fails to represent it accurately at all:

    // Dynamically update the SMS length when keys are pressed
    $("#message_content").keypress(function(e){
      var string_length = $("#message_content").text().length + 1;
      var message_count = string_length / 160;
      message_count = Math.ceil(message_count);  
      var html = '';
      html = html + message_count + ' message(s) - ' + string_length + ' characters';
      $("#message_length").html(html);

    });

    // Dynamically update the SMS length when the textarea blurs
    $("#message_content").blur(function(){
      var string_length = $("#message_content").text().length;
      var message_count = string_length / 160;
      message_count = Math.ceil(message_count);  
      var html = '';
      html = html + message_count + ' message(s) - ' + string_length + ' characters';
      $("#message_length").html(html);
    });

    // Perform an initial update on the character count
    $("#message_content").blur();

Now on the keypress function I have added 1 to the length since AFAICT the event does not have access to the content with the new character added. In any case, the event does not fire initially, and I am evaluating the blur event primarily.

I chose textarea because it accurately represents the CRLF being passed from the database, that is ultimately passed to the SMS processor.

Any help or observations are appreciated in obtaining accurate values.

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

    Fix the following problems:
    var string_length = $("#message_content").text().length + 1;
    return 1 if there’s no text demo.

    Use keyup instead.

    You can use the same come on both events.

    $("#message_content").on('blur keyup', function(){
        var string_length = $("#message_content").text().length;
        var message_count = string_length / 160;
        message_count = Math.ceil(message_count);  
        var html = '';
        html = html + message_count + ' message(s) - ' + string_length + ' characters';
        $("#message_length").html(html);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

UPDATE: Based on suggestions here, I've modified my code. To get a handle on
UPDATE: I've modified the code to drop the indexes before the inserting, but it
I modified the code here (http://www.w3schools.com/PHP/php_ajax_database.asp) to update and display my database after an
I modified this code from somewhere but I am not sure if I am
My domain model uses EntityFramework 4.1 (and I'm using code-first) to update my DB
Update: Switching to IIS Express instead of the Visual Studio Development Server fixed the
I'm using following update or insert Oracle statement at the moment: BEGIN UPDATE DSMS
I've got some heavily modified code that ultimately came from the Windows Media SDK
How do you set the cursor position in a text field using jQuery? I've
Update: Is there a way to achieve what I'm trying to do in an

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.