Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomhodgins/d6b518ab86816fc012b1 to your computer and use it in GitHub Desktop.
Save tomhodgins/d6b518ab86816fc012b1 to your computer and use it in GitHub Desktop.
Percent & Dollar inputs, linked to a Range Slider
<input id="examplePercent" type="tel" value="1250%" onblur="exampleSlide.value = this.value;exampleDollars.value = '$'+exampleSlide.value.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');examplePercent.value = exampleSlide.value+'%'">
<input id="exampleDollars" type="tel" value="$1,250" onblur="exampleSlide.value = this.value;examplePercent.value = exampleSlide.value+'%';exampleDollars.value = '$'+exampleSlide.value.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',')">
<input id="exampleSlide" type="range" min="1" max="5000" value="1250" oninput="examplePercent.value = this.value+'%';exampleDollars.value = '$'+this.value.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',')">
var examplePercent = document.getElementById('examplePercent'),
exampleDollars = document.getElementById('exampleDollars'),
exampleSlide = document.getElementById('exampleSlide');
input {
display: block;
font-size: 200%;
height: 50px;
width: 100%;
text-align: right;
}
input + input {
margin-top: 10px;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment