Search code examples
javascripthtmlmaxlength

how to get the maxlength of an input field using javascript


I just wanted to know if we could get the maxlength of an input field from javascript

<input type="password" id="password" maxlength="20" >

I tried this but it returns undefined

console.log(document.getElementById("password").maxlength);

Solution

  • document.getElementById("password").maxLength
    

    To access it with Javascript you need an uppercase 'L'

    W3 Schools Example