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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:39:22+00:00 2026-05-15T17:39:22+00:00

I have a simple HTML Form that allows the user to enter some text

  • 0

I have a simple HTML Form that allows the user to enter some text which is then sent as an SMS/TXT Message via an SMS Gateway. The user enters the message text into a textarea:

<textarea rows="10" cols="40" id="smsbody" validate = "required:true" name="MessageBody"></textarea>

They can enter as little or as much text as they like, however as each SMS is limited to 160 characters I would like to display a character counter that shows both the number of characters entered and then also calculates how many SMS credits this will use. The formula for calculating the credits is based on the total number of credits entered: if a message exceeds 160 characters, it will be split into multiple message parts. Each message part is restricted to 153 characters in length (7 bytes for headers). So a message of 160 characters will be 1 credit, 306 characters will be 2 credits, 459 characters will be 3 credits and so on.

Ideally I would like this to appear in this format:

0 characters, 1 SMS message(s)
200 characters, 2 SMS message(s)

I’m already using jQuery so happy to use a jQuery based solution as well.

Many thanks,
Steve

  • 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-05-15T17:39:23+00:00Added an answer on May 15, 2026 at 5:39 pm

    Something like this?

    Try it out: http://jsfiddle.net/kG8U2/2

    I think I understand correctly in that for 1 message, it can be 160 characters, but for more than one, the number of messages is characters divided by 153.

    HTML

    <textarea rows="10" cols="40" id="smsbody" validate = "required:true" name="MessageBody"></textarea>
    <div id='message'>
        <span id='char'>0</span> characters,
        <span id='msgs'>0</span> SMS message(s),
        <span id='remg'>160</span> remaining
    </div>​​​​
    

    jQuery

    var $chars = $('#char');
    var $msgs = $('#msgs');
    var $remg = $('#remg');
    
    $('#smsbody').keyup(function(evt) {
        var len = this.value.length;
        $chars.text(len);
        if(len <= 160) {
            $msgs.text(1);
            $remg.text(160 - len);
        } else {
            var multi = Math.ceil((len/153)) ;
            $msgs.text(multi);
            $remg.text((multi * 153) - len);
        }
    });​
    

    EDIT: Fixed a flaw where it was off by 1 character, and added a remaining counter for fun.

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

Sidebar

Ask A Question

Stats

  • Questions 499k
  • Answers 499k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer My favorite: INSERT ... SELECT It allows me to bypass… May 16, 2026 at 12:32 pm
  • Editorial Team
    Editorial Team added an answer Ah, just after posting this, I have finally found the… May 16, 2026 at 12:32 pm
  • Editorial Team
    Editorial Team added an answer Ok, so I figured out that the second error was… May 16, 2026 at 12:32 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have a simple view function that's designed to allow the user to choose
How can I use HTTP basic Authentication and have the user submit their Username
The user sees a form with many controls, including a list box. He selects
I am working with ASP.NET MVC and have a view page with a simple
What I'm trying to do is rather basic, but I might have my facts
Outline I'm building a form for a specific page, where users can make suggestions
I have built a blog application w/ ruby on rails and I am trying
On a recent project, I need have a hex mask (0x0 - 0xFF) as
I am building my portfolio website simply using HTML , Flash , and the
I have a mostly desktop programming background. In my spare time I dabble in

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.