Javascript DOM HTML Input URL maxLength Property set

Introduction

Set the maximum number of characters allowed in a URL field:

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

Click the button to set the maximum number of characters allowed in 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">
<button onclick="myFunction()">Test</button>
<p id="demo"></p>

<script>
function myFunction() {/*from w  w w.j a  v  a2  s  .  c  om*/
  document.getElementById("myURL").maxLength = "8";
  document.getElementById("demo").innerHTML = "Maximum number of characters allowed in the url field is now 8.";
}
</script>

</body>
</html>



PreviousNext

Related