Last active
December 12, 2015 00:38
-
-
Save skozz/4684931 to your computer and use it in GitHub Desktop.
jQuery: Validate min/max amount in form input
This file contains 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
<!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