I have a fairly simple form with a single HTML5 range element in it (being rendered as a slider). The code for that looks like this:
<form name="redform" id="redform" action="/">
<input id="id" name="id" type="hidden" value="<?php echo $row['id']; ?>" />
<input id="sliderRed" name="sliderRed" type="range" value="<?php echo $data[5]; ?>" min="0" max="255" />
</form>
<p class="note">Current value: <span id="redValue">0</span></p>
<div style="text-align:center; color:#FF0000" id="redresults"></div>
Accompanying this is some jQuery that executes an external php script whenever the slider is moved:
$(function(){
var redValue = $('#redValue');
$('#sliderRed').change(function(){
redValue.html(this.value);
});
$('#sliderRed').mouseup(function(){
$.post('process.php', $("#redform").serialize(), function(data) {
$('#redresults').html(data);
$('#redresults').fadeIn('slow').delay(2000).fadeOut('slow');
});
});
$('#sliderRed').change();
});
All of that works. I can move the slider around, the value updates live, and the PHP script is run when the slider is released. Here’s what’s weird. The max and min values for the range slider are set to 0 and 255. However, sometimes, when dragging the slider all the way to one end, it will only hit 1 or 254. There doesn’t seem to be any pattern to when this happens. Sometimes it goes to the full range, sometimes it can’t go all the way. This is even the case while keeping you mouse held down and dragging it back and forth.
If the max and min are changed to 256 and -1 respectively, similar behavior is observed. Sometimes it will max out at 256, and sometimes it will max out at 255. On the bottom end, it will sometimes hit -1, and sometimes it can only be dragged down to 0. This indicates to me that it doesn’t have to do with actual numbers, but with some weird “off-by-one” bug.
Any thoughts on this? I’m totally stumped…
While the suggestions provided are great (thanks Jason). It’s worth explaining why this issue actually occurs. I submitted this as a bug to the chromium bug tracker thinking it might be a chrome bug. I was half right. See the post here: http://code.google.com/p/chromium/issues/detail?id=171362
The issue is that if the slider is not at least 256 pixels long, then it’s impossible for all the values to be selectable. Using CSS, you can change the width to 256px, which eliminates the issue I described in my question.
However, this limitation makes using jQuery-UI a preferred solution, and what I will probably end up implementing.