Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 23,489 times

Related Categories

TextArea character limits

tlkelley

The following code can be used to limit the number of characters one can enter into an HTML TextArea field.

<FORM action="nextpage.asp" method=POST name="myForm">

Description:
<TEXTAREA rows=3 cols=40 name="txt_project_description"></TEXTAREA>
<BR>
<font size="1">
 Max 1000; characters remaining:  <input value="1000" size="3" name="msgCL" disabled>
</FONT>

<script language="JavaScript">
<!--
var supportsKeys = false
function tick() {
 calcCharLeft(document.forms[0])
 if (!supportsKeys) timerID = setTimeout("tick()",1000)
}

function calcCharLeft(sig) {
 clipped = false
 maxLength = 1000
 if (document.myForm.txt_project_description.value.length > maxLength)
   {
   document.myForm.txt_project_description.value = document.myForm.txt_project_description.value.substring(0,maxLength)
   charleft = 0
   clipped = true
   }
 else
   {
   charleft = maxLength - document.myForm.txt_project_description.value.length
   }
   document.myForm.msgCL.value = charleft
   return clipped
 }

tick();
//-->
</script>

</FORM>

Always working hard!!

Comments