Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create slider with decimal values using html

I want to create a slider showing decimal values like 0.0 to 0.1 using html or html5.

like image 457
user2656866 Avatar asked Oct 07 '13 09:10

user2656866


People also ask

How to create a slider in HTML?

The HTML slider input can be created on any web page by a combination of specific HTML and CSS syntaxes. You can choose any value from a specific range designed by the web developer. Users can see the value on a slider bar, also known as the HTML slider control.

What is a range slider in HTML?

What is a range slider in HTML? A range slider is an input where you select a value from a control or sliding bar. We can slide the handlebar to the right or left to produce a range. You can usually find a slider bar when manipulating your volume or brightness controls on the computer.

What is the HTML for ticks range slider?

The HTML for ticks range slider consists of four main elements, the main container, input range, and SVG elements for ticks and values. The main container is a fieldset element of HTML that contain all other elements of the range slider.

How to use price range slider with example?

Another example of price range slider with: The <input> type range elements let the user specify a numeric value being no less than a specified value, no more than another specified one. By default, the range is from 0 to 100. But you can restrict the numbers using max, min, step and value attributes. How can we improve it?


1 Answers

Add step="0.1" in your input range tag like this: <input type="range" min="0.1" max="1.0" step="0.1" value="1"> Example:

document.getElementById("scale").oninput = function() {
  document.getElementById("spanscale").innerHTML = this.value;
}
<input type="range" min="0.1" max="3.0" step="0.1" value="1" id="scale">Scale:<text id="spanscale" style="inline">1</text>

If you want to show a decimal place in integer numbers you can add this piece of code in the value output: Number(this.value).toFixed(1)

document.getElementById("scale").oninput = function() {
  document.getElementById("spanscale").innerHTML = Number(this.value).toFixed(1);
}
<input type="range" min="0.1" max="3.0" step="0.1" value="1.0" id="scale">Scale:<text id="spanscale" style="inline">1.0</text>
like image 161
Le____ Avatar answered Oct 19 '22 20:10

Le____