473,387 Members | 1,760 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

max Limit on textarea

15
How to put a max limit in the amount of characters entered into the textarea? I tried with MAXLENGTH attribute, but it didnot work.
Any help will be rally appreciated.
Thanks in advance.
Oct 13 '06 #1
7 24286
Arielle
76
I don't think there's a way to do it with the straight HTML, I think you need to use a javascript function. Something akin to...

<html>
<head>
<script language="Javascript">
function tooLong(strTest,maxLength)
{
if(strTest.value.length > maxLength)
{
strTest.value = strTest.value.substr(0,50);
}
}
</script>
</head>
<body>

<form>
<textarea name="myText" onChange="tooLong(this,50)"></textarea>
</form>
</body>
</html>

Or something like that. You could also add something like "Characters Remaining".
Oct 13 '06 #2
drhowarddrfine
7,435 Expert 4TB
<textarea cols="number of columns">
This should be done with css but I don't recall how. I'll look into it.
Oct 13 '06 #3
drhowarddrfine
7,435 Expert 4TB
As it turns out, there isn't one.
Oct 13 '06 #4
Arielle
76
<textarea cols="number of columns">
This should be done with css but I don't recall how. I'll look into it.
That limits the visible size of the textarea but doesn't control how many characters can be entered at all. You can cause a textarea to scroll for a million years if you wanted to... and despite the fact that you can add a maxlength attribute to the textarea not all browsers recognize it so it's glitchy at best. My solution won't even really work if they have javascript turned off.
Oct 13 '06 #5
<input name="textfield" type="text" value="" size="25" maxlength="20">

Try this, think this is wht you mean. (you will need to change the max length to however many characters you want to allow.
Oct 13 '06 #6
Here's another script which also gives the user a little counter to see how many characters they have left to use - may come in handy :-)

Javascript Source
Oct 13 '06 #7
swarnap
15
My problem is fixed.Thanks a lot to everyone.
Oct 16 '06 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Jay | last post by:
I have an HTML form with a textarea. When passing large amount of data in the textarea, the Processing asp pages catch an error message as follows: Error Type: (0x80020009) Exception occurred. ...
4
by: Simon | last post by:
I have another question.. Let's take a textarea with the parameter: "rows=4" (<textarea rows=4 onkeydown="CheckScrollbar()"> ) If you start typing the scrollbar at the right is not active. Only...
4
by: wing | last post by:
Hi all, I find a JavaScript that limits the field length in a textarea, but it is not completed. The script does not handle the copy and paste case. For example, says the textarea field...
5
by: Jesper Rønn-Jensen | last post by:
I have a textarea that must be limited to 70 characters. No big deal -- at least so I thought. * Textarea must not exceed 70 characters * Exceeding content must be cut off * Must work on input by...
7
by: Dean Trower | last post by:
Does anyone know a clean method of preventing scrolling altogether in a TEXTAREA (i.e. ensuring the user CANNOT type more text than fits inside the box area)? I'd like to know how, if so... It...
5
by: JohnSouth | last post by:
Hi In a TextBox I can set a maximum size for the entry. Is there a way of limiting the number of characters being entered into a TextArea control? John South www.wherecanwego.com
3
by: tadisaus2 | last post by:
Hello, I created a textarea and want to limit the maxlength to be to 255 characters. Can you help me please? <textarea rows="3" cols="55" name="abc" id="input" /></textarea> Is there any way...
1
by: nagamalli26 | last post by:
hai iam new php. i am creating admin side. i wrote this, phpcode: <?php //include_once("config.php"); $con=mysql_connect("localhost","root",""); mysql_select_db("happysalary"); ?>
3
by: teser3 | last post by:
I have the below that limits the textarea input to 500 characters but cant get the alert message to work. It doesnt show anything. Please advise. <script language="javascript"...
7
by: =?ISO-8859-1?Q?=22=C1lvaro_G=2E_Vicario=22?= | last post by:
I need to emulate the missing "maxlegth" attribute in "textarea" fields but all my Google searches either lead to obsolete scripts that overwrite the "value" property (thus losing caret position)...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.