Javascript DOM HTML Input Search maxLength Property set

Introduction

Change the maximum number of characters allowed in a search field:

document.getElementById("mySearch").maxLength = "8";

Click the button to set the maximum number of characters allowed in the search field.

View in separate window

<!DOCTYPE html>
<html>
<body>

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

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

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

<script>
function myFunction() {/*w  w w .ja v a2  s .  co  m*/
  document.getElementById("mySearch").maxLength = "8";
  document.getElementById("demo").innerHTML = "Maximum number of characters allowed was set.";
}
</script>

</body>
</html>



PreviousNext

Related