0

I wrote the below maxLength restriction on the textarea control and it works fine in IE 9.0 but doesn't work with IE 8.0.

<textarea name="commentString" rows="7" maxlength="2000">some data </textarea>

How can I set the maxLength so that it works across all browsers? would JQuery have any helper method for this?

The Light
  • 26,341
  • 62
  • 176
  • 258

2 Answers2

1
   $('textarea').keypress(function() {
  return $(this).val().length < 50;
});
Neji
  • 6,591
  • 5
  • 43
  • 66
Jayesh Amin
  • 314
  • 2
  • 12
0

It will not working below IE9.

Use this code it will work for below IE 9 version. only change version in if condtion.

if(navigator.appVersion.indexOf("MSIE .9")!=-1)
                                {
                                    $('#inputid').bind('keyup blur', function () {
                                        var $this = $(this);
                                        var len = $this.val().length;
                                        var maxlength = 3;
                                        if (maxlength && len > maxlength) {
                                            var inputvalue= $this.val().slice(0, maxlength);
                                            $this.val("");
                                            $this.val(inputvalue);
                                        }
                                    });
                                }
Ravi Chothe
  • 180
  • 5
  • 17