Hello
I have a form where I am trying to set the maximum order amount to 100.
It works fine when you click submit - if you try to order 210, it brings an error message. If the order is less than 101 (per row) then it prints the order details to the screen.
However if order details are already on the screen, it will then accept larger orders than 100.
What am I doing wrong? It is probably something simple! But it is sending me crazy.
My jquery is below, I have a Codepen here http://codepen.io/jameswinfield/pen/evvjJz
$('.add').click(function() {
if (($(this).prev().val()) < 100) {
$(this).prev().val(+$(this).prev().val() + 1);
}
});
$('.sub').click(function() {
if ($(this).next().val() > 0) $(this).next().val(+$(this).next().val() - 1);
});
$("input").on("change", function() {
if (($(this).val()) > 100) {
$('#error').html("Maximum order is 100");
} else {
$('#error').remove();
}
});
$(function() {
$('form').submit(function(e) {
e.preventDefault(); // Stop form from refreshing
if ($('#error').text() === "Maximum order is 100") {
return false;
} else {
$('#here').html('You have ordered:' + '<br><br>' + 'Item 1: ' + $('input[name="standard-box"]').val() + '<br>' + ' Item 2: ' + $('input[name="archive-box"]').val() + '<br>' + ' Item 3: ' + $('input[name="packing-tape"]').val());
}
});
});
Much appreciated
James