My name's Karl Alesbury, and I'm a C# ASP.NET contractor living in Bristol, UK. This blog is an attempt to sort out my coding gremlins or to post solutions on ridding the world of them.
Monday, 9 June 2014
Fire an event using JQuery with a delay
Sometimes when you're building some javascript to validate a field, you don't necessarily want that field to be constantly re-evaluated.
An example of this is when you're validating a password. You want to make sure that the password is valid after the user's finished entering it, but you don't really want them to have to click a 'validate' button. Wouldn't it be neater if it just evaluated it 'on the fly'? Most password validation tools also have a nice progress bar that changes colour when you start producing more sensible passwords, going from scary red to calming green. If your bar changed colour after every key press, it'd become a quite cumbersome and CPU-intensive process. This is where bindWithDelay comes in!
Using this example, the registered event will wait until the user lifts their finger and does nothing further within this field for one second prior to running the password validation function. This super-handy little plugin is available courtesy of http://briangrinstead.com.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment