We have a text box in which the user must enter some data. However, this data must not exceed 500 characters. To achieve this, we have implemented the following function called the KeyUp event:
function keyupMaxLimit(obj, maxlen) {
if (parseInt(obj.value.length) > maxlen) {
$(obj).val($(obj).val().substr(0,maxlen));
}
}
This works: the user cannot enter more than what is expected. We also have a function associated with the Change event of the same text field to detect changes and do our magic.
$(document).on("change", "#myTextBox", function () {
});
This also works: when the user changes the text called by the function.
However, and this is our problem, these two functions do not work together. If, for example, the user enters more characters that he / she should use, the first function will truncate the text, and the second will not be called!
, , , - / . ? ? Change , .
. : http://jsfiddle.net/jpaires/dpujx/
"12345" . ( "a-ok" ). , "123456", , ( "a-ok" ). Juhana:)