Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

question re: <TEXTAREA> in HTML

Status
Not open for further replies.

SaltyDuke

Programmer
Sep 18, 2002
140
IE
hello

i'm fairly new to HTML and am in need of a little help. I'm making a form with a <TEXTAREA> field (for people to enter their addresses), but i'm a little worried that people will put too much information in it... or just hold down the enter key for ages! as the output of this form is connected to a printer on my web server i don't really want that to happen.

so... how do i limit the amount of characters that can be entered in the <TEXTAREA> field? is it something to do with rows and columns? help! anyone who can answer this question is instantly more clever and helpful than all the HTML tutorials on the net :)

thanx in advance
TheSaltyDuke

[pipe]
 
Well... there is no simple property you can add to a textarea that will limit the character count. There are ways that you can achieve this though!

Basically you add some javascript to the onblur of the textarea and every time it blurs you check the number of characters... if there are more than you want to allow... then you can throw up an alert and force the textarea to retain focus again.

Here is my attempt at this:

Code:
<textarea name="description" rows="5" cols="40" onblur="if ((this.value).length > 250) {this.focus(); alert('You are limited to 250 characters in this text field (you have '+(this.value).length+')');}">Type your message here</textarea>

All the best,
Jeff
 
Don't think you can restrict entry to a textarea simply through HTML tags. I would suggest either using JavaScript to validate / trim the data entered or, since the user is entering their address, why not use separate textboxes for the address lines as these can be restricted to a set length.
 
Have a look at:
thread216-813027

Hope this helps.

Pete.


Web Developer &amp; Aptrix / Lotus Workplace Web Content Management (LWWCM) Specialist
w: e: Pete.Raleigh(at)lclimited.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top