Skip to content

Instantly share code, notes, and snippets.

@lavrovpy
Created March 18, 2019 19:46
Show Gist options
  • Save lavrovpy/9d5f781b3d7229439c4969eb31fa164f to your computer and use it in GitHub Desktop.
Save lavrovpy/9d5f781b3d7229439c4969eb31fa164f to your computer and use it in GitHub Desktop.
JS count plus/minus
<div id="input_div">
<input type="text" size="25" value="1" id="count">
<input type="button" value="-" id="moins" onclick="minus()">
<input type="button" value="+" id="plus" onclick="plus()">
</div>
<div id="notice" style="color:red;"></div>
var count = 1;
var countEl = document.getElementById("count");
function plus(){
count++;
countEl.value = count;
if (count > 8) {
document.getElementById('notice').innerHTML = "We currently don't have this quantity readily available which may impact our turn-around time.";
}
}
function minus(){
if (count > 1) {
count--;
countEl.value = count;
if (count < 8) {
document.getElementById('notice').innerHTML = "";
}
}
}
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment