Javascript Reference - HTML DOM Input URL maxLength Property








The maxLength attribute sets the maximum number of characters allowed in the URL field. The default value is 524288.

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

Browser Support

maxLength Yes 10.0 Yes Yes Yes

Syntax

Return the maxLength property.

var v = urlObject.maxLength

Set the maxLength property.

urlObject.maxLength=number




Property Values

Value Description
number Set the maximum number of characters allowed in the URL field. Default value is 524288

Return Value

A Number type value representing the maximum number of characters allowed in the URL field.

Example

The following code shows how to set the maximum number of characters allowed in a URL field.


<!DOCTYPE html>
<html>
<body>
<!--   ww  w  .  j  a  va2s  .co m-->
Homepage: <input type="url" id="myURL">
<button onclick="myFunction()">test</button>
<script>
function myFunction() {
    document.getElementById("myURL").maxLength = "8";
}
</script>
</body>
</html>

The code above is rendered as follows:





Example 2

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


<!DOCTYPE html>
<html>
<body>
Homepage: <input type="url" id="myURL" maxlength="30">
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {<!--from w w w.  j ava  2  s  . c  o m-->
    var x = document.getElementById("myURL").maxLength;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The code above is rendered as follows: