I am restricting the user to enter a max limit(40Char) of characters in a text area.
Calling this below JS function on onKeyUp event of textarea.
But when i copy paste a content which is more than 40chars, not gettinng pop-up(Alert) until i do a keyup/down on the textarea.
Is there a way to get alert without keyup/down after pasting into textarea?
Thanks in advance!
function checkMaxLength(textBox, e, maxLength) {
if (textBox.value.length > maxLength - 1) {
alert("* You have reached max limit ");
textBox.value = textBox.value.substr(0, maxLength);
} else {
alert(maxLength - textBox.value.length + " characters remaining");
}
I have tried the below approach, It is working fine on IE,Safari,Chrome but not working on Mozilla Firefox, Any thoughts on this?
<HTML><head></head><body>
<form name="myForm">
Text: <input type="text" name="myText"
önKeyUp = "fncKeyLength(this);">
</form>
<script>
function fncKeyLength(text){
if (window.event.ctrlKey){
if (window.event.keyCode == 86) {
alert("<br />The string is this long: " + text.length);
}
}}
</script></body></HTML>