My task is to create a counter/limiter, which pops a window when the limit is reached. I made this code:
$(document).ready(function() {
$('#message-input').keyup(updateCounter);
});
function updateCounter() {
var value = $('#message-input').val();
if (value.length > 256) {
alert('Túl hosszú az üzenet!');
return false;
}
var remaining = 256 - value.length;
$('#counter').text(remaining);
return true;
}
This code works great, but has a big problem: if the limit is reached, i can press anything, always the window pops up, even if i press backspace. How can i correct that?