HTML DOM Input Range object


The HTML DOM Input Range object is associated with the <input> element with type “range”. We can create and access an input element with type range using the createElement() and getElementById() method respectively.

Properties

Following are the properties for the Input range object −

Sr.NoProperty & Description
1autocomplete
To set or return the autocomplete attribute value of a range control.
2autofocus
To set or return if the range slider control should get focus automatically when the page loads or not
3defaultValue
To set or return the range slider control default value.
4disabled
To set or return if the slider control has been disabled, or not.
5form
To return the reference of the form containing the slider control
6List
To return the reference to the datalist containing the slider control
7Max
To set or return the max attribute value of the slider control.
8Min
To set or returns the min attribute value of the slider control.
9Name
To set or return the name attribute value of the slider control.
10Step
To set or return the value of the step attribute of the slider control.
11Type
To return the form element type for the slider control.
12value
To set or return the value attribute value of a slider control.

Methods

Following is the method for the password object −

Sr.NoMethod & Description
1stepDown()
To decrement the slider control value by a given number
2stepUp()
To increment the slider control value by a given number.

Example

Let us look at an example for the Input Range object −

 Live Demo

<!DOCTYPE html>
<html>
<head>
<script>
   function rangeCreate() {
      var R = document.createElement("INPUT");
      R.setAttribute("type", "range");
      document.body.appendChild(R);
}
</script>
</head>
<body>
<h1>Input range object</h1>
<p>Create an input field with type range by clicking the below button</p>
<button onclick="rangeCreate()">CREATE</button>
<br><br>
VOLUME:
</body>
</html>

Output

This will produce the following output −

On clicking the CREATE button −

In the above example −

We have created a button CREATE that will execute the rangeCreate() method when clicked by the user −

<button onclick="rangeCreate()">CREATE</button>

The rangeCreate() method uses the createElement() method of the document object to create the <input> element by passing “INPUT” as a parameter. The newly created input element is assigned to variable R and using the setAttribute() method we create a type attribute with value range.

Remember, setAttribute() creates the attribute and then assigns value if the attribute doesn’t exist previously. Finally using the appendChild() method on document body we append the input element with type range as the child of the body −

function createPASS() {
   var R = document.createElement("INPUT");
   R.setAttribute("type", "range");
   document.body.appendChild(R);
}

Updated on: 22-Aug-2019

131 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements