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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:01:27+00:00 2026-06-04T11:01:27+00:00

I am trying to use max-length in a textarea with jQuery Mobile, and I

  • 0

I am trying to use max-length in a textarea with jQuery Mobile, and I have run into a strange problem – the problem is that with or without the return false used in javascript, the textarea stops me from entering text anywhere from 15 to 60 characters too early..

The maxLength property is set to 1150, and I am able to type between 1090 and 1115 characters. I don’t know if it is a function of using copy and paste, as this is the only way I have tested it, but it seems weird.

Here is the code:

$(document).delegate('#main','pageinit',function() {
    $('#title,#description').keypress,function(e){

        var cur=$(this).val().length,
        max=$(this).prop('maxLength'), rem=max-cur,
        ch=$(this).parents('.ui-bar').find('.char-rem'),
        red=$(this).parents('.ui-bar').find('.char-rem.red'),           
        green=$(this).parents('.ui-bar').find('.char-rem.green');

        ch.children('span').html(rem);

        if(rem <= 10)
        {
            green.removeClass('green')
            ch.addClass('red');
        } else {    
            red.removeClass('red')
            ch.addClass('green')
        }
        if(rem == 0)
        {
            if(e.which!= 8)
            {
                return false;
            }
        }

    })
})

What happens every time, is that I get down to some low amount of characters remaining – but more than zero – and I can’t type anymore.
The same thing happens if I remove the following:

if(rem == 0)
{
    if(e.which!= 8)
    {
        return false;
    }
}

I have tried this with keydown and keyup as well, and inside or outside pageinit, and made various other adjustments, and I have verified the number of characters in the textarea with the textarea textLength property, and each time the result is the same.

Right now, I am using Chromium to test this, and I haven’t tested it elsewhere, but I want to see if there is something I am just missing.

Any clues?

  • 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-04T11:01:28+00:00Added an answer on June 4, 2026 at 11:01 am

    My previous note about the line breaks wasn’t the answer. The answer was that each time the function got called, it was reading the maxLength property newly.
    For some reason, in reading the maxLength property, the count was getting messed up.

    When I switched the variable for the maxLength value to a number (1150) instead of a making it read the property, it worked perfectly.

    EDIT WITH REAL ANSWER:

    Actually, the real answer was that I had unclosed html tags, so who knows what it was doing. When I fixed the tags, all was well

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

Sidebar

Related Questions

I am trying to use a textarea form entry which I have some javascript
I am having a strange issue. I am trying to use jQuery autocomplete with
So I am trying to use the CSS hack to set the max-height for
I was trying use a set of filter functions to run the appropriate routine,
Hi I'm trying use a datepicker on a field I have. I'm trying to
I'm trying to get some input from a user and use that input in
I am trying to use Scala to find the parameter to a function that
I have a Django query and some Python code that I'm trying to optimize
I'm trying to use a JQuery UI slider to allow users to select a
im trying to use javascript in my textarea to display text until the user

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.