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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:29:26+00:00 2026-06-15T19:29:26+00:00

we have a textarea and it should allow only 300 char’s. we are able

  • 0

we have a textarea and it should allow only 300 char’s. we are able to control it via any keyboard press event using

onkeydown="limitText(this,300);" 
onkeyup="limitText(this,300);

where limitText is as follows

limitText = function (limitField, limitNum) {
    if (limitField.value.length > limitNum) {
        limitField.value = limitField.value.substring(0, limitNum);
    }
},

But we are unable to control mouseClick paste via this….Please share any idea on this.
Please Note: i checked few solutions on internet but couldnt solve. i know its a small issue, but as am new to jQuery (infact to the whole web world), am unable to ping at the right place…..

  • 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-15T19:29:27+00:00Added an answer on June 15, 2026 at 7:29 pm

    To handle all input modern browsers have oninput event

    Here the sample that do what you asked using this event:

    $('.limited').bind('input',function() {
        var $t=$(this);
        var max=$t.data('maxchars');
    if ($t.val().length>max) {
        $t.val($t.val().substr(0,max));
    }
    });​
    

    DEMO

    for old browsers you should use keyup,keydown+onpaste:

    $('.limited').bind('keyup keydown paste',function(e) {
        var $t=$(this);
        setTimeout(function(){ 
        var max=$t.data('maxchars');
    if ($t.val().length>max) {
        $t.val($t.val().substr(0,max));
    }
        },0);
    });​
    

    OLD BROWSERS DEMO

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

Sidebar

Related Questions

I have a textarea I have submitted via a form. Then I get the
I have a textarea that I'm able to edit with the jeditable plugin but
I have seen plenty of code snippets to force a <Textarea> to have only
I have a textarea on my page where i allow users to write text.
I have a textarea that I have a blur event attached to. I don't
I have a textarea which when in focus should empty the text holder and
I have a textarea field where I allow users to type in plain text
I have textarea containing one or more URLs, along with other text content. I
I have textarea in my site(link shortening site) i want to user enter some
I have a textarea with this content: <textarea id=text> Hello! Who am I? This

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.