Input Search maxLength Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Search

Description

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

The default value is 524288.

Set the maxLength property with the following Values

Value Description
number Sets the maximum number of characters allowed in the search field.

Return Value

A Number, representing the maximum number of characters allowed in the search field

The following code shows how to get the maximum number of characters allowed in a specific search field:

Demo Code

ResultView the demo 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() {//from w w  w .j  a  v  a  2s.co m
    var v = document.getElementById("mySearch").maxLength;
    document.getElementById("demo").innerHTML = v;
}
</script>

</body>
</html>

Related Tutorials