Today is a good day to code

Internet Explorer, input tags, and the maxlength attribute

Posted: December 31st, 1969 | Author: | Filed under: Uncategorized | No Comments »

Internet Explorer, input tags, and the maxlength attribute

Picture of IrvinI've been doing a ton of javascript over the past few months, and an issue came up with the maxlength attribute. It turns out that Internet Explorer doesn't honor the maxlength in any way for input fields.

The worse thing is that firefox does. The only real way around this is to use javascript either on blur, or on the submission of the form. Here is some javascript that will get the job done. It isn't perfect, but with some fiddling you should be able to get it perfect:

function forceTextBoxLength(length,object){
if(object.value.length >= length){
object.value = object.value.substring(0,(length));
}
}