View Single Post
  #49 (permalink)  
Old 02-21-2008, 01:59 AM
prasannavigneshr prasannavigneshr is offline
D-Web Incredible
 
Join Date: Feb 2007
Posts: 1,321
prasannavigneshr is on a distinguished road
Send a message via MSN to prasannavigneshr
Thumbs up ColdFusion Tips & Tricks - Restricting the amount of data a user can enter in a text

Restricting the amount of data a user can enter in a textarea form field


If you want to limit how many characters a user enters in a Text Area form field, you can use the onKeyDown function to check the length of the string with the key the user just pressed. If it exceeds a certain value, you can actually cancel that keypress.

Example HTML/CFML code:


Code:
<html>
<head>
<script language="Javascript1.2">

function checkLength()
{
  if (document.MyForm.Desc.value.length > 9)
  {
    alert('You may only enter 10 characters in the description field.');
    return false;
  }
}

</script>
</head>
<body onLoad="document.MyForm.Desc.focus()">
<form name="MyForm">
Please tell us a <i>little</i> bit about yourself (10 characters max)<br>
<textarea name="Desc" rows="4" cols="40" wrap="off" onKeyDown="return checkLength(event,'1')"></textarea>
</form>
</body>
__________________
Prasanna Vignesh
MCPD | Web Developer
Reply With Quote