1
votes

In HTML code we are using input type range but the problem is when we use focus event then in Firefox its not working properly.

here is my code

var p = document.getElementById("price"),
  res = document.getElementById("result");
test = document.getElementById("test");

p.addEventListener("input", function() {
  test.focus();
  test.value = "$" + p.value;
}, false);
#result {
  font-size: 2em;
}
<div style="margin-top: 1em">
  <h2>Price</h2> $51
  <input id="price" type="range" min="51" max="360" value="" />$360
</div>
<input type="text" name="test" value="" id="test" />

slider is not sliding smoothly in mozilla but its working fine in chrome

2
Whats the issue? Its working on firefox, "range" element behave different in firefoxSatpal
please check this fiddle in mozilla jsfiddle.net/itruser/n7u5960f/1 slider is not working smothly while in chrome slider working fineNIKHIL PARIHAR
I have made some improvements in my answer, please have a look.Rehan Haider

2 Answers

1
votes

When focus is shifted to input field then you will not be able to slide the slider. Use following code to resolve it

var p = document.getElementById("price"),
    res = document.getElementById("result"),
    test=document.getElementById("test"),
    timeout = null;

p.addEventListener("input", function() 
{
   test.value = "$" + p.value;
   clearTimeout(timeout);
   timeout = setTimeout(function(){ test.focus(); }, 400);
}, false); 
#result {
    font-size: 2em;
}
<div style="margin-top: 1em">
    <h2>Price</h2>
    $51<input id="price" type="range" min="51" max="360" value="" />$360
</div>
<input type="text" name="test" value="" id="test"/>

Use setTimeout to focus on input field after a pause when slider was clicked

0
votes

Try updating your Firefox browser, because I ran your code and the slider is running smoothly on both the browsers(Chrome and Firefox) on my side and in your code you haven't given a reference to the JavaScript code. I assume that was present in your main code. Tell me if you are facing the problem even after updating.