Hit enter after type your search item

5 demos of jQuery range slider by using a plugin

The range slider

To enhance the user experience if your website takes user input by way of web forms, adding the simple slider or range slider for required information can be good. For example, for selecting age group, salary range, or any other numeric requirement can be shown and selectable by way of visual selectors.

In this tutorial, I am going to show you such a plug-in which is jQuery based and can be easily integrated into web pages. So, let me start with a few demos and a setting up guide on the way. (plug-in can be downloaded here)

A simple jQuery slider demo

In this example, a simple slider is created by using the jRange plug-in. This slider can be used for a numeric value selection, for example, number of creditors, year of experience or some other. Have a look at the demo and setting up steps.

jQuery slider

See online demo and code

Follow these steps for setting up this plug-in in your web page.

Step 1:

Include the jRange CSS file in the <head> section.

<link href=”css/jquery.range.css” rel=”stylesheet” type=”text/css”>

Step 2:

Write the markup where you simply need to create an input type hidden and assign it the class name which is referred in the <script> part. For example, I used the simple-slider class name.

<input class=”simple-slider” type=”hidden” value=”25″/>

Step 3:

Just above the </body> tag, place the jQuery library and plug-in JS file,:

<script src=”js/jrange/jquery.range.js”></script>

Step 4:

Finally, the code for initiating the slider with certain options. You may use many available options, a few of which I will use in coming examples.

For example,

  • from sets the value where slider value should start from.
  • to: specifies the maximum number.
  • step: specifies the gap.
  • scale: In the output of demo, you can see the scale with these numbers

A demo of creating jQuery range slider

In this example, a range slider is created by using the plug-in. The markup section remains the same as in above example. Just the <script> part is changed where isRange option is added.

jQuery range slider

See online demo and code

By using the isRange : true, the slider acts as the range slider where a user may select the minimum and maximum values.

See the complete code in the demo page.

An example of showing the selected values in range slider

As working in the real-time project, you will need the selected value of simple and values for range sliders in order to save it in the database or perform a certain action based at this. Since this slider is most probably is used in the web forms.

Let me show you, how you may get the value selected by the user. For that, I have used the change event of the input type hidden, that acts as a slider. As you click somewhere in the slider, the alert will show both values of the selected range.

jQuery range slider values

See online demo and code

Only this code is added in the <script> section of above example:


 

Using blue theme rather than green demo

The included CSS file with plug-in contains other themes that you may specify in the <script> section for changing the color of slider.

In this example, I have specified the theme-blue and the outcome is as follows:

jQuery range slider blue

See online demo and code

This is how the option of theme is added in the <script> section:


 

Using your own custom theme

By adding a few classes in the plug-in CSS file or in the <style> section, you may refer your own theme in the <script> section that matches the rest of the form or website’s theme.

In this example, I have taken theme classes from the CSS file and placed those in the <style> section under the <head> tag. I named it theme-maroon and referred this in the <script> section as well.

Have a look at the demo online:

jQuery range slider custom CSS

See online demo and code

The following classes for themes are taken and changed:


 

Similarly, you can change the height, width, circle and other properties by changing the in the main CSS file or overriding in the <style> section.

This div height required for enabling the sticky sidebar