Friday, August 28, 2015

Character Counter for ASP.Net TextArea Using jQuery

















<script type=“text/javascript” language=“javascript”>
var characterLimit = 150;
$(document).ready(function () {
$(‘#remainingCharacters’).html(characterLimit);
$(‘#<%=txtMessage.ClientID %>’).bind(‘keyup’, function () {
var charactersUsed = $(this).val().length;
if (charactersUsed > characterLimit) {
charactersUsed = characterLimit;
$(this).val($(this).val().substr(0, characterLimit));
$(this).scrollTop($(this)[0].scrollHeight);
}
var charactersRemaining = characterLimit – charactersUsed;
$(‘#remainingCharacters’).html(charactersRemaining);
});
});
</script>


<textarea id=“txtMessage” runat=“server” ></textarea>
<br />
<span><span id=“remainingCharacters”></spancharacters remaining </span>

you can use it in comment sections or sending sms message Content

No comments:

Post a Comment