TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Count the maximum length of textbox using Javascript
Purushottam Rathore
Apr 30, 2020
19.9
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
Count the maximum length of textbox using Javascript
<%@ Page Language=
"C#"
AutoEventWireup=
"true"
CodeFile=
"MexLength.aspx.cs"
Inherits=
"MexLength"
%>
<!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>Maximum length counter</title>
<script language=
"JavaScript"
>
function
textCounter(field, countfield, maxlimit) {
if
(field.value.length > maxlimit)
// if too long...trim it!
field.value = field.value.substring(0, maxlimit);
else
countfield.value = maxlimit - field.value.length;
}
</script>
</head>
<body>
<form id=
"Form1"
name=
"myform"
runat=
"server"
>
<asp:TextBox ID=
"TextBoxMessage"
runat=
"server"
TextMode=
"MultiLine"
Height=
"60px"
onkeydown=
"textCounter(TextBoxMessage,LengthCount,25)"
onkeyup=
"textCounter(TextBoxMessage,LengthCount,25)"
></asp:TextBox>
<input readonly type=
"text"
name=
"LengthCount"
size=
"3"
maxlength=
"3"
value=
"25"
>
</form>
</body>
</html>
Count the maximum length of textbox using Javascript
Next Recommended Reading
Allow Only Numeric Values and allow Only one DOT in TEXTBOX using JavaScript