You are here: Reference > JavaScript > client-side > HTML DOM > objects > nodes and tags > input:range

input:range object

Browser support:
Creates a slider control.
With the slider control the user can set a value by moving an indicator. The lowest and the highest values of the slider control can be set with the min and max properties. The step property defines the step size. The value of the control can be set with the value property.
This control is one of the form controls.
The contents of the control can be submitted to a server if the following conditions are met:
  • A form element must contain the slider control.
  • The action property of the container form must be set to the URL of the server.
  • The name property of the slider control must be specified and non-empty.
When the container form is submitted, the name and the value of the control are sent as a name/value pair.
You can access the value of the control with the value property. Sometimes it is useful to check the value before submitting. See Example 2 for details.
The base interface, through which you can add new functionalities to the slider control, is the HTMLInputElement interface.

Syntax:

Methods that return the object:
var inputObj = document.createElement ("input");   inputObj.type = "range"
The base interface, through which you can add new functionalities to the slider control, is the HTMLInputElement interface.
If you want to see the HTML objects by categories, please visit this page.
HTML page for this element: input:range

Possible members:

Properties
Methods
Events
Style properties
accessKey
Sets or retrieves an access key to an element.
attributes
Represents a collection of attribute nodes that belong to an element.
baseURI
10
Returns the base URL for the object.
className
Sets or retrieves the style class or classes that belong to the element.
clientHeight
Returns the height of the visible area for an object, in pixels. The value contains the height with the padding, but it does not include the scrollBar, border, and the margin.
clientLeft
Returns the width of the left border in pixels.
clientTop
Returns the height of the top border in pixels.
clientWidth
Returns the width of the visible area for an object, in pixels. The value contains the width with the padding, but does not include the scrollBar, border, and the margin.
contentEditable
Sets or retrieves whether the contents of the object are editable.
currentStyle
Represents the computed style settings for an element.
defaultValue
Specifies or returns the initial value of the object. The initial state can be set with the value attribute in HTML.
dir
Sets or retrieves the text direction as related to the lang property.
disabled
Sets or retrieves the state of an object for user interaction.
form
Returns a reference to the form element in which the object is placed.
forms
Represents a collection of all form elements in the current document.
hspace
Specifies or returns the number of pixels to use as a margin at the left and right sides of the object.
id
Sets or retrieves a unique identifier for the object.
isContentEditable
Returns a Boolean value that indicates whether the contents of the object are editable by the user.
lang
Specifies or returns the language of the element.
localName
Returns the local part of the qualified name of the current node.
max
Sets or retrieves the maximum value of a range type input object (slider).
min
Sets or retrieves the minimum value of a range type input object (slider).
name
Sets or retrieves the name of a form control that affects the contents of the message submitted to the server.
namespaceURI
Sets or returns the namespace URI of the current node.
nextElementSibling
Returns a reference to the next child element of the current element's parent.
nextSibling
Returns a reference to the next child of the current element's parent.
nodeName
Returns the name of the current node.
nodeType
Returns an integer that indicates the type of the node.
nodeValue
Sets or returns the value of the current node.
offsetHeight
Returns the height of the visible area for an object, in pixels. The value contains the height with the padding, scrollBar, and the border, but does not include the margin.
offsetLeft
Returns the left position of an object relative to the left side of its offsetParent element, in pixels.
offsetParent
Returns a reference to the closest ancestor element in the DOM hierarchy from which the position of the current element is calculated.
offsetTop
Returns the top position of the object relative to the top side of its offsetParent element, in pixels.
offsetWidth
Returns the width of the visible area for an object, in pixels. The value contains the width with the padding, scrollBar, and the border, but does not include the margin.
outerHTML
Sets or retrieves the outer HTML content (the source code including the opening and closing tags) of an element.
outerText
Sets or returns the text content of an element including the text content of its descendants.
ownerDocument
Returns the document object that contains the current node.
parentElement
Returns the parent element of the object in the DOM hierarchy.
parentNode
Returns the parent element of the current node in the DOM hierarchy.
previousElementSibling
Returns a reference to the previous child element of the current element's parent.
previousSibling
Returns a reference to the previous node of the current element's parent.
readOnly
Sets or retrieves whether the contents of the element are changeable.
size
Specifies or returns the width of a control, in characters.
sourceIndex
Returns the position of the current object in the all collection of the document.
step
Sets the discrete step size of the input:range element.
style
Represents the inline style settings for an element or a CSS rule.
tabIndex
Specifies or returns the tabbing order for keyboard navigation using the TAB key.
tagName
Returns the tag name of the current element.
title
Specifies or returns a tooltip for an element.
type
Sets or retrieves the type of the input element.
value
Specifies or returns the value of the control.
vspace
Specifies or returns the number of pixels to use as a margin at the top and bottom sides of an object.

Example HTML code 1:

This example illustrates the use of the slider control:
<form method="post" action="#URL#">
    Username: <input type="text" name="userName" />
    <br /><br />
    Your bet: <input type="range" name="bet" min="20" max="200" step="20" value="40" />
    <br /><br />
    <input type="submit" value="Send" />
</form>
Did you find this example helpful? yes no

Example HTML code 2:

This example shows how to display the value of a slider control:
<head>
    <style>
        .sliderValue {
            margin-left: 20px;
            padding: 3px;
            background-color: #d0d0f0;
            border: 1px solid #808080;
        }
    </style>
    <script type="text/javascript">
        function OnSliderChanged (slider) {
            var sliderValue = document.getElementById (slider.id + "Value");
            sliderValue.innerHTML = slider.value;
        }

        function Init () {
            var slider = document.getElementById ("slider1");
            OnSliderChanged (slider);
            var slider = document.getElementById ("slider2");
            OnSliderChanged (slider);
        }
    </script>
</head>
<body onload="Init ()">
    0<input type="range" id="slider1" min="0" max="100" step="25" onchange="OnSliderChanged (this)" />100
    <span id="slider1Value" class="sliderValue"></span>
    <br /><br /><br />
    -100<input type="range" id="slider2" min="-100" max="100" step="10" onchange="OnSliderChanged (this)" />100
    <span id="slider2Value" class="sliderValue"></span>
</body>
Did you find this example helpful? yes no

Example HTML code 3:

This example checks the value of the slider control before submitting the form:
<head>
    <script type="text/javascript">
        function CheckAndSubmit () {
            var betForm = document.getElementById ("betForm");
            var betSlider = document.getElementById ("betSlider");

            if (betSlider.value == 200) {
                var bet = confirm ("Are you sure you want to bet the maximum?");
                if (!bet)
                    return;
            }

            betForm.submit ();
        }
    </script>
</head>
<body>
    <form id="betForm" method="post" action="#URL#">
        Username: <input type="text" name="userName" />
        <br />
        Your bet: <input type="range" name="bet" id="betSlider" min="20" max="200" step="20" value="200" />
        <br /><br />
        <input type="button" value="Send" onclick="CheckAndSubmit ()" />
    </form>
</body>
Did you find this example helpful? yes no

External links:

User Contributed Comments

Post Content

Post Content