Skip to content Skip to sidebar Skip to footer

Max Length Of Textarea Is Not Working On Ie8

From research on internet, max length attribute is not working on IE 8 and 9 To resolve the problem I tried a solution from here , it use with the other function which is for pres

Solution 1:

The code in the question effectively disables typing from keyboard when the limit has been reached. To impose the restriction on pasted content too, you need to handle other events, too. The following code truncates the textarea content to the given length. This is not good usability (you should probably signal an attempt to exceed the limit, instead of silent truncation, and you could have a character counter on the page to help the user), but it does what was asked for:

<textareamaxlength=2000onchange="testLength(this)"onkeyup="testLength(this)"onpaste="testLength(this)"
></textarea><script>var maxLength = 2000;
functiontestLength(ta) {
  if(ta.value.length > maxLength) {
    ta.value = ta.value.substring(0, maxLength);
  }
}
</script>

Solution 2:

Just for some hstory on this, maxlength on a textarea is a new HTML5 feature which was only first supported by IE in 10. IE 9 and below never supported it.

Solution 3:

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);
                                        }
                                    });
                                }

Solution 4:

Simply add onpaste fixed the problem

<textareaname="q<%=countNo%>_ans"rows="3"cols="55"maxlength="2000"style="resize: none;"onkeyup="new do_resize(this);"onKeyPress="return ( this.value.length < 2000); onpaste="return ( this.value.length < 2000);"></textarea>

Post a Comment for "Max Length Of Textarea Is Not Working On Ie8"