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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:09:11+00:00 2026-06-15T22:09:11+00:00

i need functionality that every character after 5th line in textarea will get deleted

  • 0

i need functionality that every character after 5th line in textarea will get deleted ,
and 5th line will only contain max 15 chars.

i can achieve this little bit using “caret”, but it will only add text at particular
cursor position,
i m using kepress event and setinterval (onFocus of textarea) function
which will clear extra text from textarea, and clearInterval (onBlur of textarea)

function insertTextAtCaret(el, text) 
{
    var val = el.value, endIndex, range;
    if (typeof el.selectionStart != "undefined" && typeof el.selectionEnd != "undefined") {
        endIndex = el.selectionEnd;
        el.value = val.slice(0, endIndex) + text + val.slice(endIndex);
        el.selectionStart = el.selectionEnd = endIndex + text.length;
    } else if (typeof document.selection != "undefined" && typeof document.selection.createRange != "undefined") {
        el.focus();
        range = document.selection.createRange();
        range.collapse(false);
        range.text = text;
        range.select();
    }
}
  • 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-15T22:09:13+00:00Added an answer on June 15, 2026 at 10:09 pm
    function charCountTextarea(textAreaId,e,limit,lineLen)
    {   
    
        var code = e.charCode || e.keyCode;
    
        newLines = $("#"+textAreaId).val().split("\n").length;
        var t = $("#"+textAreaId)[0];
        var lineIndex = t.value.substr(0, t.selectionStart).split("\n").length-1;
        console.log('val t :'+$("#"+textAreaId).val()+' line index : '+lineIndex+' new lines '+newLines);
    
        if(lineIndex == 10 && $("#"+textAreaId).val().split("\n")[lineIndex].length>(lineLen+1) && code!=8 && code!=46 && code!=33 && code!=34 && code!=35 && code!=36 && code!=37 && code!=38 && code!=39 && code!=40)
        {
            $("#"+textAreaId).val(($("#"+textAreaId).val()).substring(0, $("#"+textAreaId).val().length - 1));
            alert('You are reached to limit');
            return false;
        }
    
        if(lineIndex<5)
        {
            $("#"+textAreaId).val($("#"+textAreaId).val().wordWrap(lineLen, "\n", 0));
        }
        var countLine1 = $("#"+textAreaId).val().split("\n")[0].length;
    
        if($("#"+textAreaId).val().split("\n")[lineIndex].length>lineLen)  // which will count the total line char condition
        {
            console.log("In condition : ");
            if(code!=8 && code!=46 && code!=33 && code!=34 && code!=35 && code!=36 && code!=37 && code!=38 && code!=39 && code!=40)
            {
                // to insert next line              
                insertTextAtCaret(document.getElementById(textAreaId), "\n");
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing an IOS app. I need a functionality that includes undo and
I have some functionality that I need in all my classes which derive from
I have common functionality that I need to access from all screens of my
I need to add functionality to the close button in my class that extends
I need to access functionality from win32 dll , for that I am using
i need to add some functionality to an asp.net application that allows the positioning
I need an advice on piece of functionality that I am ought to implement.
I need to set up some kind of e-store with search functionality. For every
I need scheduling functionality on my .NET MVC website and I came across Quartz.net
I am working on one project where there is a functionality need to implement

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.