Skip to main content

How to add counter function in textbox




<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Counter.aspx.cs"
Inherits="Counter" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>

<script type="text/javascript">
function textCounter(field, countfield, maxlimit)

{
/*
* The input parameters are: the field name;
* field that holds the number of characters remaining;
* the max. numb. of characters.
*/
if (field.value.length > maxlimit) // if the current length is more than allowed
field.value =field.value.substring(0, maxlimit); // don't allow further input
else
countfield.value = maxlimit - field.value.length;


}

</script>

</head>
<body>
<form id="form1" runat="server">
<div>
<textarea name="message" cols="25" rows="4"
wrap="PHYSICAL" id="message" onkeydown="textCounter(this.form.message,
this.form.remLen,50);"

onkeyup="textCounter(this.form.message, this.form.remLen,50);
"
></textarea>
<input name="remLen" type="text" id="remLen" value="50" size="3"
maxlength="3" readonly />
</div>
</form>
</body>
</html>

Comments

Popular posts from this blog