Search code examples
javascriptinputtextfieldmaxlength

JavaScript MaxLength not working on new textfields


I add new text fields with Javascript:

var input = document.createElement("input");
input.type = "text";
input.name = "blabla";
input.maxlength = '4';
input.size = "4";
input.id = "blabla";
container.appendChild(input);

It appears maxlength doesn't do anything..I have tried "" '' or without any quotations. What's wrong? In chrome when I inspect element I get:

<input type="text" name="blabla" size="4" id="blabla">


Solution

  • You have to use maxLength not maxlength

    input.maxLength = 4;
    

    Note about the L.