HTML DOM Input URL maxLength Property

HTMLWeb DevelopmentFront End Technology

The HTML DOM Input URL maxLength property returns/sets the maxLength property for input URL. If not defined this property returns ‘-1’.

Syntax

Following is the syntax −

  • Returning maxLength attribute
inputURLObject.maxLength
  • Set maxLength property to a number
inputURLObject.maxLength = number

Example

Let us see an example of Input URL maxLength property −

 Live Demo

<!DOCTYPE html>
<html>
<head>
<title>Input URL maxLength</title>
<style>
   form {
      width:70%;
      margin: 0 auto;
      text-align: center;
   }
   * {
      padding: 2px;
      margin:5px;
   }
   input[type="button"] {
      border-radius: 10px;
   }
</style>
</head>
<body>
<form id="Google">
<fieldset>
<legend>URL-maxLength</legend>
<label for="URLSelect">URL :
<input type="url" id="URLSelect" maxLength="10">
</label>
<input type="button" onclick="logIN()" value="Log In">
<input type="button" onclick="changeMaxLength()" value="Change Maxlength">
<div id="divDisplay"></div>
</fieldset>
</form>
<script>
   var divDisplay = document.getElementById("divDisplay");
   var inputURL = document.getElementById("URLSelect");
   divDisplay.textContent = 'Maxlength: '+inputURL.maxLength;
   function changeMaxLength() {
      inputURL.maxLength += 10;
      divDisplay.textContent = 'Maxlength: '+inputURL.maxLength;
   }
   function logIN(){
      if(inputURL.value !== '')
         divDisplay.textContent = 'Could not identify url, Redirecting to '+inputURL.form.id;
   }
</script>
</body>
</html>

Output

This will produce the following output −

Before clicking ‘Change Maxlength’ button −

After clicking ‘Change Maxlength’ button −

After clicking ‘Log In’ button and setting email input −

raja
Published on 26-Jul-2019 12:13:03
Advertisements