I have a HTML form featuring an Input Range that I am using so a user can set their age between 18 to 100.
The input range displays fine. However I want the output value to be shown to the user as they are sliding the range up/down.
I figured the best way to do this was with CSS/Jquery.
My problem is that no out put values are being displayed. Please can someone show me where I am going wrong?
My HTML
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<div class="container">
<div class="about_edit">
<h3>About Me</h3>
<form action="" method="post" name="edit">
<label>Age</label>
<input type="range" id="start" name="age" min="18" max="100">
<output for="age" onforminput="value = age.valueAsNumber;"></output>
<input name="submit" type="submit" value="Login" />
</form>
</div>
</div>
On the same page I have my Jquery:
<script>
// DOM Ready
$(function() {
var el, newPoint, newPlace, offset;
// Select all range inputs, watch for change
$("input[type='range']").change(function() {
// Cache this for efficiency
el = $(this);
// Measure width of range input
width = el.width();
// Figure out placement percentage between left and right of input
newPoint = (el.val() - el.attr("min")) / (el.attr("max") - el.attr("min"));
// Janky value to get pointer to line up better
offset = -1.3;
// Prevent bubble from going beyond left or right (unsupported browsers)
if (newPoint < 0) { newPlace = 0; }
else if (newPoint > 1) { newPlace = width; }
else { newPlace = width * newPoint + offset; offset -= newPoint; }
// Move bubble
el
.next("output")
.css({
left: newPlace,
marginLeft: offset + "%"
})
.text(el.val());
})
// Fake a change to position bubble at page load
.trigger('change');
});
</script>
<script>
var minValue, maxValue;
if (!el.attr("min")) { minValue = 0; } else { minValue = el.attr("min"); }
</script>
Then I have My CSS:
<style>
.about_edit{
border-bottom:1px solid #ccc;
}
label {
width: 140px;
text-align: left;
margin-top:20px;
}
input {
width: 100%;
padding:5px;
margin: 8px 0;
box-sizing: border-box;
}
.edit {
width: 100%;
height:35px;
margin:0 auto;
box-sizing: border-box;
line-height: 20px;
padding:10px;
}
output {
position: absolute;
background-image: linear-gradient(top, #444444, #999999);
width: 40px;
height: 30px;
text-align: center;
color: white;
border-radius: 10px;
display: inline-block;
font: bold 15px/30px Georgia;
bottom: 175%;
left: 0;
margin-left: -1%;
}
output:after {
content: "";
position: absolute;
width: 0;
height: 0;
border-top: 10px solid #999999;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
top: 100%;
left: 50%;
margin-left: -5px;
margin-top: -1px;
}
</style>