Pages

Sunday, October 3, 2010

JQuery validation on multiline textbox for character count


-------------------------------------------------------------------
JQuery validation on multiline textbox for character count
-------------------------------------------------------------------



<script src="../scripts/jquery-1.4.2.js" type="text/javascript"></script>

<script language="javascript">

$(document).ready(function() {
//Set the Variable for max length
var MaxLength = 50;

$('#<%=txtCount.ClientID%>').val(MaxLength);
$('#<%=txtprojectdesc.ClientID%>').keyup(function() {
if ($(this).text().length > MaxLength) {
$(this).text($(this).text().substring(0, MaxLength));
}
$('#<%=txtCount.ClientID%>').val(MaxLength - $(this).text().length);
});
$('#<%=txtprojectdesc.ClientID%>').blur(function() {
if ($(this).text().length > MaxLength) {
$(this).text($(this).text().substring(0, MaxLength));
}
$('#<%=txtCount.ClientID%>').val(MaxLength - $(this).text().length);
});
});
</script>
--------------------------------------
<asp:TextBox ID="txtprojectdesc" CssClass="textbox_reg" TextMode="MultiLine" Rows="5" Width="200px" runat="server"></asp:TextBox><br />

<asp:TextBox ID="txtCount" MaxLength="3" ReadOnly="true" BorderWidth="0" CssClass="textbox_reg" Width="20px" Font-Names="verdana" Font-Size="XX-Small"
ForeColor="#ad1800" runat="server"></asp:TextBox><span class="helptext">Characters left.</span>





0 comments:

Post a Comment

 

CodeAddict.com | Copyright 2009 Tüm Haklar? Sakl?d?r | Free Blogger Templates by GoogleBoy Download Free Wordpress Templates. Unblock through unblock myspace proxy, Hillsongs by Guitar Song Chords