I want to prevent user to enter text in textarea once it reaches a max character limit. What was happening that when i reached to max limit then my text-area scroll-bar move
You could directly give maxlength to textarea to disable itself. But, you want to showing appropriate message then use keyup event for default behavior and textarea length for calculating charcter and display suitable message.
HTML
jQuery
$(function(){
var max = parseInt($("#tarea").attr("maxlength"));
$("#count").text("Characters left: " + max);
$("#tarea").keyup(function(e){
$("#count").text("Characters left: " + (max - $(this).val().length));
if($(this).val().length==max)
$("#msg").text("Limit Reached....");
else
$("#msg").text("");
});
});
Demo Fiddle