Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

onChange event for HTML5 range

Currently the onChange event on my range inputs is firing at each step.

Is there a way to stop this event from firing until the user has let go of the slider?

I'm using the range to create a search query. I want to be able to run the search every time the form is changed but issuing a search request at each step of the slider's movement is too much.


Here's the code as it stands:

HTML:

<div id="page">     <p>Currently viewing page <span>1</span>.</p>     <input class="slider" type="range" min="1" max="100" step="1" value="1" name="page" /> </div> 

JavaScript:

$(".slider").change(function() {     $("#query").text($("form").serialize()); }); 

Does that help?

like image 948
WilliamMayor Avatar asked Mar 02 '11 09:03

WilliamMayor


People also ask

How do you define Onchange in HTML?

Definition and UsageThe onchange attribute fires the moment when the value of the element is changed. Tip: This event is similar to the oninput event. The difference is that the oninput event occurs immediately after the value of an element has changed, while onchange occurs when the element loses focus.

How do you pass an event Onchange?

To pass multiple parameters to onChange in React:Pass an arrow function to the onChange prop. The arrow function will get called with the event object. Call your handleChange function and pass it the event and the rest of the parameters.


1 Answers

Use for final selected value:

 $(".slider").on("change", function(){console.log(this.value)}); 

Use to get incremental value as sliding:

$(".slider").on("input", function(){console.log(this.value)}); 
like image 138
kravits88 Avatar answered Oct 08 '22 06:10

kravits88