Introduction:
here I will explain how to use jQuery to limit number of characters in textarea(textbox) even copy and paste text or jQuery restrict textbox(textarea) length even copy and paste text in textbox with example.
here I will explain how to use jQuery to limit number of characters in textarea(textbox) even copy and paste text or jQuery restrict textbox(textarea) length even copy and paste text in textbox with example.
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>jQuery Limit Number of Characters in a TextArea</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type='text/javascript'>
$(function() {
$('#textarea1').keyup(function() {
var desc = $('#textarea1').val();
var len = desc.length;
if (desc.length >= 150) {
this.value = this.value.substring(0, 150);
}
$('#spntxt').text(150 - len + ' Characters Left');
});
});
</script>
</head>
<body>
<textarea id="textarea1" cols="20" rows="8"></textarea><br/>
<span id="spntxt"> 150 Characters left</span>
</body>
</html>
No comments:
Post a Comment