I have a form that lists a remaining quantity of a product and below it an input field that lets you put a quantity into the form to submit for purchase.
I have the remaining quantity wrapped in a span with an ID. On keyup, I want to compare the value of the span with the input entered into the field.
If the input is greater than the value in the span, on keyup, I want to change the value of the input to 0 or the equivalent of the span ID value.
Here is my javascript I am trying to use to accomplish this:
<script>
$(document).ready(function () {
document.getElementById('one_and_done_stool_QTY_check').keyup(Qty_check);
function Qty_check(){
var QTY1check = document.getElementById('one_and_done_stool_QTY_check').value;
var QTY1remain = document.getElementById('one_and_done_stool_QTY_remain').innerHTML;
if (QTY1check.value > QTY1remain.innerHTML)
alert("NOPE");
{document.getElementById("one_and_done_stool_QTY_check").value = 0;}
};}
</script>
And here is the html:
<span id="one_and_done_stool_QTY_remain">2</span>
<input id="one_and_done_stool_QTY_check" type="text" name="one_and_done_stool">