I want to change the maxlength of a textbox with JavaScript or jQuery: I tried the following but it didn't seem to help:
var a = document.getElementsByTagName('input');
for(var i=0; i<a.length; i++) {
if((a[i].type!= 'radio')||(a[i].type!= 'checkbox'))
a[i].maxlength = 5;
}
document.getElementsByTagName('input')[1].maxlength="3";
$().ready(function()
{
$("#inputID").maxlength(6);
});
What am I doing wrong?
The max length property is camel-cased: maxLength
jQuery doesn't come with a maxlength method by default. Also, your document ready function isn't technically correct:
Also, since you are using jQuery, you can rewrite your code like this (taking advantage of jQuery 1.6+):
without jQuery you can use
set the attribute, not a property
I Used this along with vars and selectors caching for performance and that did the trick ..
Not sure what you are trying to accomplish on your first few lines but you can try this:
You can make it like this: