HTML DOM Input URL type Property



The HTML DOM Input URL type property returns/sets type of Input URL.

Syntax

Following is the syntax βˆ’

  • Returning string value
inputURLObject.type
  • Setting type to string value
inputURLObject.type = stringValue

String Values

Here, β€œstringValue” can be the following βˆ’

stringValue
Details
email
It defines that input type is email
url
It defines that input type is url
radio
It defines that input type is radio
tel
It defines that input type is tel and a number keypad is shown for input

Example

Let us see an example for Input URL type property βˆ’

 Live Demo

<!DOCTYPE html>
<html>
<head>
<title>Input URL type</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>
<fieldset>
<legend>URL-type</legend>
<label for="URLSelect"></label>
<input type="url" id="URLSelect" >
<input type="button" onclick="getTypeOfInput()" value="What to enter?">
</fieldset>
</form>
<script>
   var labelSelect = document.querySelector("label");
   var inputURL = document.getElementById("URLSelect");
   function getTypeOfInput() {
      labelSelect.innerHTML = inputURL.type.toUpperCase()+': ';
   }
</script>
</body>
</html>

Output

This will produce the following output βˆ’

Before clicking β€˜What to enter?’ button βˆ’

After clicking β€˜What to enter?’ button βˆ’

Updated on: 2019-07-30T22:30:26+05:30

151 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements