This is a discussion on How do you limit the length (in characters) of text entered in a textarea form field within the HTML, CSS and Javascript Coding Techniques forums, part of the Web Development category; How do you limit the length (in characters) of text entered in a textarea form field...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
|
#1
| |||
| |||
| How do you limit the length (in characters) of text entered in a textarea form field |
|
#2
| |||
| |||
| Hi, You can check the length of textarea field using javascript... i have given the sample code.it will throw an error message if the size exceeds 20 characters in textarea field. Code: <html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script type="text/javascript">
function checkLength(pmId)
{
vTextValue=document.getElementById(pmId).value;
if(vTextValue.length > 20)
{
alert("Exceeds the limit only 20 characters allowed");
vTextValue=vTextValue.substr(0,19);
document.getElementById(pmId).value=vTextValue;
}
}
</script>
</head>
<body>
<form action="" method="post" name="frmTest">
<label>Field1:</label>
<textarea id="txtArea" onkeypress="checkLength(this.id)" cols="25" rows="3"></textarea>
</form>
</body>
</html> Hope it will help you...
__________________ ....................... Thanks, Venkatbi... Last edited by venkatbi : 03-24-2008 at 01:35 AM. Reason: alignment change |
|
#3
| |||
| |||
| <script language="JavaScript"><!-- function validate(what) { if (what.length > 10) { alert('Must be less than 10 characters'); return false; } return true; } //--></script> <form name="formName" onSubmit="return validate(documents.formName.textName.value)"> <textarea name="textName" onChange="validate(this.value)"></textarea> </form> |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Number sign in Textarea Field causing php problems | karisegraves | PHP Programming | 1 | 01-04-2009 04:20 AM |
| Prefill a text form field with the current date. | itbarota | HTML, CSS and Javascript Coding Techniques | 1 | 03-18-2008 08:09 PM |
| Date/Time stamp a form field as the form is submitted | itbarota | HTML, CSS and Javascript Coding Techniques | 2 | 01-17-2008 07:47 PM |
| How can I clear the form field values after the user has submitted the form for clien | itbarota | HTML, CSS and Javascript Coding Techniques | 1 | 11-01-2007 10:39 PM |
| How do I check that text entered in a text form field is an integer? | itbarota | HTML, CSS and Javascript Coding Techniques | 2 | 10-25-2007 11:25 PM |
Our Partners |