Javascript DOM HTML Input Search maxLength Property get

Introduction

Get the maximum number of characters allowed in a specific search field:

var x = document.getElementById("mySearch").maxLength;

Click the button to display the value of the maxlength attribute of the search field.

View in separate window

<!DOCTYPE html>
<html>
<body>

Search: <input type="search" id="mySearch" maxlength="30">

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {//from   w  w w .  j a v  a 2s  .c o  m
  var x = document.getElementById("mySearch").maxLength;
  document.getElementById("demo").innerHTML=x;
}
</script>

</body>
</html>

The maxLength property sets or gets the maxlength attribute of a search field.

The maxLength attribute sets the maximum number of characters allowed in the search field.

To get the width of an email field, use the size property.

The maxLength property accepts and returns a number type value.




PreviousNext

Related