Skip to content

Instantly share code, notes, and snippets.

@ccschmitz
Created March 11, 2013 14:46
Show Gist options
  • Save ccschmitz/5134744 to your computer and use it in GitHub Desktop.
Save ccschmitz/5134744 to your computer and use it in GitHub Desktop.
Some JS to ensure that a user doesn't enter a value that is less than or greater than the min/max values allowed for a number input.
$('#element').change(function() {
var $this = $(this);
if ($this.val() > $this.attr('max')) {
$this.val($this.attr('max'));
} else if ($this.val() < $this.attr('min')) {
$this.val($this.attr('min'));
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment