Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

limiting the rows in a text area

Posted on 1999-07-26
14
Medium Priority
?
212 Views
Last Modified: 2013-11-15
I want to set a maximum number of rows accepted by a textarea. I know you can set the amount visible, e.g. cols="4" rows="5" but text areas will still let you scroll down and will not limit the maximum input area to these settings. How do I limit this?
0
Comment
Question by:jamba
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 3
  • +3
14 Comments
 
LVL 3

Expert Comment

by:messentary
ID: 1852409
The maxlength attribute will limit the ammount of text placed within a text area.  The code would look like:

<input type="text" name="Name" SIZE="30" maxlength="30">

Give it a try and get back yo me.
0
 

Author Comment

by:jamba
ID: 1852410
I thought of using a good old text field and limiting it's length as you suggested, but I need to allow new line characters because I am using "\n" to seperate input. Basically I need an input form that will allow multiple lines but I need to limit the total number of lines allowed. Is that more clear?
0
 

Author Comment

by:jamba
ID: 1852411
Adjusted points to 100
0
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
LVL 3

Expert Comment

by:messentary
ID: 1852412
The maxlength attribute will limit the ammount of text placed within a text area.  The code would look like:

<input type="text" name="Name" SIZE="30" maxlength="30">

Give it a try and get back yo me.
0
 
LVL 3

Expert Comment

by:messentary
ID: 1852413
Ignore the above statement
0
 
LVL 7

Expert Comment

by:nettrom
ID: 1852414
let me see if I've got this straight.

you don't want to limit the size of the text entered in the textarea, but simply limit the amount of lines entered?

use a JavaScript and count the number of newlines entered?
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 1852415
In IE4+, you can limit the number of characters in a textarea with javascript like this ( imitates maxlength of 200 ):

  <TEXTAREA name='mytextarea' wrap width='40' height='5'
    onKeyUp='this.value=this.value.substring(0,200);'></textarea>


This will also work in netscape with some modifications ...

0
 

Author Comment

by:jamba
ID: 1852416
Hmm... I guess this is a more difficult question than I originally anticipated. All I want is to be able to make an input box with a limited amount of rows. Is there no maxrow variable? Is it possible (as it very well should be) in simple HTML to limit the number of lines entered, just as you can limit the number of characters? There's hope in knightEknight's comment: if you can set the word wrap and you can set  the maxlength, isn't that effectively limiting the amount of lines possible? Maybe that's what he's suggesting, but I don't think that it requires java script. I could be wrong. Any more suggestions?
0
 
LVL 7

Expert Comment

by:nettrom
ID: 1852417
not really.  if you only limit the number of total characters I could make that 99% newlines and 1 character, and it would still be correct.

what I believe you have to do is:

numLines = 0;
for(i = 0, i < n = textarea.value.length; i++) {
  if(textarea.value.charCodeAt(i)  == 10) {
    numLines++;
  }
}

then check the amount found in numLines.

I did some testing regarding newlines read from form elements (specifically a textarea) a while back, and Netscape 4.x and both IE4 & 5 under Win 98 uses the code pair of "13 10" as a newline (CR + LF I believe).  my Netscape 4.08 under linux uses "10 10".  therefore I believe looking for simply "10" is easiest.  I don't know what happens on a Mac though (or anything else).
0
 
LVL 2

Expert Comment

by:djsansui
ID: 1852418
you could just tell the user that it only accepts X number of lines, and then just change the script so that it deletes all entiries after that number of lines.  This shouldn't be hard at all.

As far as the HTML, try something like scrolling="no".  I don't know if it works, but give it a try.
0
 
LVL 2

Expert Comment

by:iamari
ID: 1852419
I think if you use something like <TEXTAREA NAME=myText ROWS=5 COLS=6 WRAP=VIRTUAL> you will get rid of scrollbars

Ion
0
 
LVL 7

Expert Comment

by:nettrom
ID: 1852420
'wrap="virtual"' won't remove the scrollbars.  there'll always be the vertical scrollbar.  what 'wrap="virtual"' does is that it tells the browser to wrap lines so they show up nicely on screen, but not send any end-of-line characters to the server.  just like E-E does.

without the attribute it's up to the browser to wrap or not.  there's also a setting for making it wrap _and_ send the EOLs to the server.
0
 
LVL 2

Accepted Solution

by:
djsansui earned 300 total points
ID: 2171693
I've gone through all of my HTML documentation, and there is no attribute that will accomplish what you want by using a textarea.

What I suggest is that you use separate text fields for each line you wish to use, something like:
<input type="text" name=1><br>
<input type="text" name=2><br>
<input type="text" name=3><br>
<input type="text" name=4><br>

In this example, it limits it to 4 lines.  For example, www.bluemountain.com uses this method for its online greeting cards.  You will, however, need to modify the script slightly to allow for this.
0
 

Author Comment

by:jamba
ID: 2173094
Thanks, I ended up doing what you suggested. Seems like a bit of a limitation of HTML to me...
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we will learn how to backup a VMware farm using Nakivo Backup & Replication. In this tutorial we will install the software on a Windows 2012 R2 Server.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
This tutorial will walk an individual through the process of installing the necessary services and then configuring a Windows Server 2012 system as an iSCSI target. To install the necessary roles, go to Server Manager, and select Add Roles and Featu…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

670 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