HTML DOM Input Range type property


The HTML DOM Input Range type property is associated with the input element having its type=”range”. It will always return range for the input range element.

Syntax

Following is the syntax for range type property −

rangeObject.type

Example

Let us look at an example for the range type property −

 Live Demo

<!DOCTYPE html>
<html>
<body>
<h1>Input range type Property</h1>
<form>
VOLUME <input type="range" id="RANGE1" name="VOL">
</form>
<p>Get the above input element type by clicking the below button</p>
<button type="button" onclick="rangeType()">GET Type</button>
<p id="Sample"></p>
<script>
   function rangeType() {
      var P=document.getElementById("RANGE1").type;
      document.getElementById("Sample").innerHTML = "The type for the input field is: "+P ;
   }
</script>
</body>
</html>

Output

This will produce the following output −

On clicking the GET Type method −

In the above example −

We have created an input field contained inside a form having type=“range”, id=“RANGE1”, name=“VOL” −

<form>
VOLUME <input type="range" id="RANGE1" name="VOL">
<form>

We have then created a button “GET Type” that will execute the rangeType() method on being clicked by the user −

<button type="button" onclick="rangeType()">Get Type</button>

The rangeType() method gets the input element using the getElementById() method and assigns its type attribute value to variable P. This variable is then displayed in the paragraph with id “Sample” using its innerHTML property −

function rangeType() {
   var P = document.getElementById(“RANGE1").type;
   document.getElementById("Sample").innerHTML = "The type for the input field is : "+P;
}
raja
Published on 22-Aug-2019 16:12:41
Advertisements