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>

Advertisements

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

  1. Bee Colony Removal Benoni Says:

    bookmarked!!, I like your site!

    • Chandra Dev Says:

      Thank you.

  2. What Is The Symptoms Of Herpes Says:

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

  3. berenice.rankin Says:

    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!

  4. DanielCole Says:

    Interesting post )
    http://wndbl0v3.com my blog


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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: