IT Community - Software Programming, Web Development and Technical Support

How do you limit the length (in characters) of text entered in a textarea form field

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...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > HTML, CSS and Javascript Coding Techniques

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 03-22-2008, 02:03 AM
GDevakii GDevakii is offline
D-Web Sr.Programmer
 
Join Date: Aug 2007
Posts: 138
GDevakii is on a distinguished road
Question How do you limit the length (in characters) of text entered in a textarea form field

How do you limit the length (in characters) of text entered in a textarea form field
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 03-23-2008, 10:12 PM
venkatbi venkatbi is offline
D-Web Programmer
 
Join Date: Jul 2007
Posts: 80
venkatbi is on a distinguished road
Default Re: How do you limit the length (in characters) of text entered in a textarea form fi

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 02:35 AM. Reason: alignment change
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-24-2008, 08:41 PM
GDevakii GDevakii is offline
D-Web Sr.Programmer
 
Join Date: Aug 2007
Posts: 138
GDevakii is on a distinguished road
Smile Re: How do you limit the length (in characters) of text entered in a textarea form fi

<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>
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Prefill a text form field with the current date. itbarota HTML, CSS and Javascript Coding Techniques 1 03-18-2008 09:09 PM
Date/time stamp a form field as the form is submitted itbarota HTML, CSS and Javascript Coding Techniques 1 02-06-2008 10:16 PM
Date/Time stamp a form field as the form is submitted itbarota HTML, CSS and Javascript Coding Techniques 2 01-17-2008 08: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 11: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-26-2007 12:25 AM


All times are GMT -7. The time now is 01:10 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0