Count in maximum text size for textarea
Description
The following code shows how to count in maximum text size for textarea.
Example
<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
src='http://code.jquery.com/jquery-1.9.1.js'></script>
<script type="text/javascript"
src="http://code.jquery.com/mobile/1.3.0-beta.1/jquery.mobile-1.3.0-beta.1.js"></script>
<link rel="stylesheet" type="text/css"
href="http://code.jquery.com/mobile/1.3.0-beta.1/jquery.mobile-1.3.0-beta.1.css">
<script type='text/javascript'>//<![CDATA[
$(function(){<!-- w ww . jav a2 s.c o m-->
$("#topic").keyup(function(e) {
var tam = $(this).val().length;
if (tam <= 61700){
$("#maxCarac").html(tam +" typed characters. The maximum allowed is 61700");
} else {
alert("You have reached the maximum text size.\nPlease break your text into more than one topic.");
$("#topic").val($("#topic").substring(61700));
}
});
});//]]>
</script>
</head>
<body>
<div id="verTopico" class="oculto tipos">
<label for="topico">Topic: <span style="font-style: italic;"
id="maxCarac">0 typed characters. The maximum allowed is 61700</span></label>
<textarea name="topic" id="topic" style="height: 15em !important;"></textarea>
</div>
</body>
</html>