Skip to content

Instantly share code, notes, and snippets.

@skozz
Last active December 12, 2015 00:38
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 skozz/4684931 to your computer and use it in GitHub Desktop.
Save skozz/4684931 to your computer and use it in GitHub Desktop.
jQuery: Validate min/max amount in form input
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!--
* @cazascripts / angelrmolina.com
-->
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(document).ready(function(){
var limit = 18; // Define the limit you want
$('#amount').on('blur', function(){
var quantity = $(this).val();
console.log(quantity, limit);
if(quantity < limit) {
$('#amount').val(limit);
};
});
});
</script>
</head>
<body>
<form action="" method="post" accept-charset="utf-8">
<input type="text" id="amount" name="amount">
</form>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment