How to fix the limit on TextBox using Javascript code ?


Here is the simple JavaScript code to do this task

<%@ Page Title=”” Language=”C#” MasterPageFile=”~/MasterPage.master” AutoEventWireup=”true” CodeFile=”JavaScriptTest.aspx.cs” Inherits=”Default2″ %>

<asp:Content ID=”Content2″ ContentPlaceHolderID=”ContentPlaceHolder1″ Runat=”Server”>
<p>
Comment
<asp:TextBox ID=”txt_HeadLine” onkeyup=”chkmsg1(‘txt_HeadLine’)”  runat=”server” Height=”97px” TextMode=”MultiLine”
Width=”586px”></asp:TextBox>
&nbsp;<asp:Label ID=”lbl_HeadlineCount” runat=”server” Text=””></asp:Label>
</p>

<script language=”javascript”>

function chkmsg1(as) {
var a = document.getElementById(‘<%=txt_HeadLine.ClientID%>’).value.length;
var len = document.getElementById(‘<%=txt_HeadLine.ClientID%>’).value.length;
var str = document.getElementById(‘<%=txt_HeadLine.ClientID%>’).value;

a = parseInt(a);
a = 75 – a;

if (a >= 0) {
document.getElementById(‘<%=lbl_HeadlineCount.ClientID%>’).innerHTML = a + ‘ Remaining’;
}
else {
var x = str.substring(0, 75);
document.getElementById(‘<%=txt_HeadLine.ClientID%>’).value = x;
document.getElementById(‘<%=txt_HeadLine.ClientID%>’).blur();
}
return true;
}

</script>

</asp:Content>

Advertisement

5 thoughts on “How to fix the limit on TextBox using Javascript code ?

  1. What Is The Symptoms Of Herpes June 15, 2014 / 10:17 am

    I am sure this post has touched all the internet viewers, its really really
    nice paragraph on building up new webpage.

  2. berenice.rankin October 4, 2014 / 2:47 am

    Spot on with this write-up, I actually think this amazing site needs a great deal more attention. I’ll
    probably be back again to read through more, thanks for the
    advice!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.