I\'m trying to set the maxlength on input fields dynamically using JavaScript. Apparently that is a problem in IE, and I found part of the solution.
$(\"inpu
Because I had some trouble with the answer from @James I wrote sth that worked even when copy-pasting stuff, and especially when working with IE8 and down. My implementation uses jQuery and its live-events.
jQuery(function () {
$('body').on('keydown.maxlength_fix', 'textarea[maxlength]', function (e) {
var $this = $(this);
window.setTimeout(function () {
var val = $this.val();
var maxlength = $this.attr('maxlength');
if (val.length > maxlength) {
$this.val(val.substr(0, maxlength));
}
}, 4);
});
});