A Pen by Andrey Lavrov on CodePen.
Created
March 18, 2019 19:46
-
-
Save lavrovpy/9d5f781b3d7229439c4969eb31fa164f to your computer and use it in GitHub Desktop.
JS count plus/minus
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = ""; | |
} | |
} | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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