P
princeofcode
Hey all,
The following function counts for number of characters in a text area
and displays
error msg when it exceeds a maximum limit
I would like to optimize this function so that its highly portable
and elegant
if anybody could do. It will be of great help. Also I would like to add
mincount
ie: a text less than mincount should raise error
----------------------
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<script language="Javascript">
function checkchars(txtArea,maxLength)
{
txtArea.value = txtArea.value.slice(0, maxLength);
if(txtArea.value.length>=maxLength)
{
alert('Only 20 Characters are Allowed');
}
//Display Remaining characters can type in TextBox
document.getElementById('txtDisplay').value =maxLength -
txtArea.value.length
}
</script>
<TITLE> New Document </TITLE>
</HEAD>
<BODY>
<TEXTAREA name="txtAreaResume" rows="5" wrap="VIRTUAL" cols="40"
onkeyup="checkchars(this,20)"></TEXTAREA>
No of Characters Allowed: <INPUT TYPE="TEXT" name="txtDisplay"
id="txtDisplay" value=20 MaxLength=3 disabled=disabled
style="width:25px;border=0" > <BR>
</BODY>
</HTML>
The following function counts for number of characters in a text area
and displays
error msg when it exceeds a maximum limit
I would like to optimize this function so that its highly portable
and elegant
if anybody could do. It will be of great help. Also I would like to add
mincount
ie: a text less than mincount should raise error
----------------------
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<script language="Javascript">
function checkchars(txtArea,maxLength)
{
txtArea.value = txtArea.value.slice(0, maxLength);
if(txtArea.value.length>=maxLength)
{
alert('Only 20 Characters are Allowed');
}
//Display Remaining characters can type in TextBox
document.getElementById('txtDisplay').value =maxLength -
txtArea.value.length
}
</script>
<TITLE> New Document </TITLE>
</HEAD>
<BODY>
<TEXTAREA name="txtAreaResume" rows="5" wrap="VIRTUAL" cols="40"
onkeyup="checkchars(this,20)"></TEXTAREA>
No of Characters Allowed: <INPUT TYPE="TEXT" name="txtDisplay"
id="txtDisplay" value=20 MaxLength=3 disabled=disabled
style="width:25px;border=0" > <BR>
</BODY>
</HTML>