Javascript DOM HTML Input URL maxLength Property get

Introduction

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

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

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

elements with type="url" are not supported in Safari.

View in separate window

<!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  a v a2s  .c  om*/
  var x = document.getElementById("myURL").maxLength;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

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

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

The maxLength property returns a Number representing the maximum number of characters allowed in the URL field.




PreviousNext

Related