Jump to content

Suggestion for improving Input Range step Property


Roland
 Share

Recommended Posts

Hi,

I have a suggestion for improving the Input Range step Property, here: https://www.w3schools.com/jsref/prop_range_step.asp

I found that the Try It Yourself code lacks context as it doesn't show a value, min or max attribute in the input element so the step attribute doesn't have much meaning.
https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_range_step

Here is my suggestion for improving the code. You may want to remove the Try it button seeing as the innerHTML is being updated each time the slider changes:

Thanks,
Roland
 

<!DOCTYPE html>
<html>
<body>

Points: 1 <input type="range" id="myRange" value="5" step="1" min="1" max="10"> 10

<p>Click the button to display the value and the step attribute of the slider control.</p>

<button onclick="myFunction()">Try it</button>

<p><strong>Note:</strong> input elements with type="range" are not supported in IE 9 and earlier versions.</p>

<p id="demo"></p>

<script>
function myFunction() {
  var step = document.getElementById("myRange").step;
  var value = document.getElementById("myRange").value;
  document.getElementById("demo").innerHTML = 'step:' + step + ', value:' + value;
}

document.getElementById("myRange").addEventListener('input', function(e) {
	myFunction();
});

myFunction();

</script>

</body>
</html>

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...