Multiline TextBox expand as characters exceed space

Posted on 2009-04-16
Last Modified: 2012-05-06
I want to put a 2 line multiline textbox on the page.

As the user fills up the two lines, I want it to grow another line, etc.; so they still see the entire box as they're typing.
Maybe also have the ability for a maxrows of so much.

Is there anyway to do this?

Using VB and 3.5 sp1.

Question by:BobCSD
    LVL 17

    Accepted Solution

    You should do this in javascript.

    This code might come in handy for me too :)

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
        <script type="text/javascript" language="javascript">
    function Resize(obj) {
      var txt = obj.value;
      var maxRows = 10;
      var maxChar = 100;
      var arrTxt = txt.split(/[\n\f\r]/);
      var cntLines = arrTxt.length;
      for (var i = 0; i < arrTxt.length ; i ++ )
        if (Math.ceil(arrTxt[i].length / 20) > 1) {
          cntLines += Math.ceil(arrTxt[i].length / 20) - 1;
      document.getElementById("Text1").value = arrTxt.length + " breaks ; " + cntLines + " lines";
      if (obj.rows > maxRows) {
        alert('Max Rows Reached!');
        return false;
      if (txt.length > maxChar) {
        alert('Max Characters Reached!');
        obj.value = obj.value.substr(0, maxChar)
        return false;
      if (obj.rows == maxRows) return true;
      obj.rows = cntLines + 1;
      return true;
        <textarea id="TextArea1" cols="20" rows="2" onkeyup="return Resize(this)"></textarea>
        <input id="Text1" type="text" />

    Open in new window

    LVL 1

    Author Closing Comment

    excellent! Thanks!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API ( has made its way into the popular lexicon of the English language.  A few years ago, …
    I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now