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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:29:15+00:00 2026-06-01T01:29:15+00:00

This is difficult to track down for me as a JS newbie. I am

  • 0

This is difficult to track down for me as a JS newbie.

I am writing a simple (?) Script that shows me under a textarea (which is meant for writing SMS messages) how many characters the current SMS has left and how many SMS I have written so far.

I have the following JavaScript in my header:

<script type='text/javascript'>
    function CheckCount(text, length) {
        var MaxLength = new Number(length);
        messages = Math.ceil(((text.value) ? text.value.length : 0) / 160);
        remaining = messages * 160 - (((text.value) ? text.value.length : 0) % (messages * 160) || messages * 160);
        if (text.value.length == 0) { messages = 1; remaining = 160; }
        document.getElementById('messages').innerText = messages + ' SMS';
        document.getElementById('remaining').innerText = remaining + ' Characters remaining';
    }
</script>

In the body of the website I put this:

<textarea name="sms_text" cols="35" rows="5" onKeyUp="javascript:CheckCount(this,4000);" onChange="javascript:CheckCount(this,4000);"></textarea>
<p style="margin-left:174px">
    <span id="remaining">160 Characters remaining</span> |
    <span style="clear:both" id="messages">1 SMS</span>
</p>

This works fine in Opera, Safari and Chrome. Firefox and IE have their issues.

Please don’t beat me too much. I am just starting with JavaScript and after a day of tedious searching I cannot get to the solution. 🙂

  • 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-01T01:29:17+00:00Added an answer on June 1, 2026 at 1:29 am

    You don’t need to include javascript: in your textarea handler attributes:

    While the above is true, your problem is caused by the use of innerText. Changing to innerHTML works in FireFox.

    http://jsfiddle.net/ZTRFA/1/

    And to make it work in IE8 it is necessary to declare messages and remaining. I also removed the redundant line var MaxLength = new Number(length);.

    http://jsfiddle.net/ZTRFA/2/

    function CheckCount(text, length) {
           var messages = Math.ceil(((text.value) ? text.value.length : 0) / 160);
           var remaining = messages * 160 - (((text.value) ? text.value.length : 0) % (messages * 160) || messages * 160);
           if (text.value.length == 0) { messages = 1; remaining = 160; }
           document.getElementById('messages').innerHTML = messages + ' SMS';
            document.getElementById('remaining').innerHTML = remaining + ' Characters remaining';
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This has been very difficult to track down and has caused me a great
This might be a bit difficult to explain in writing, so please bear with
This seems like a simple question, but it is difficult to search for. I
This is a problem I have been trying to track down for a couple
I'm not sure how difficult this but I have an array and would like
not sure why I find this so difficult. Here is the html code: <tr>
This is a difficult and open-ended question I know, but I thought I'd throw
difficult to look this up if it has been asked previously since I don't
I know this will be a difficult question, so I am not necessarily looking
I hope this isn't too difficult, obviously you can call HTML tags such as

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.