Notice This is a beta feature offered by Google. Also this is automatic translation, which means the results are often inacurate and/or hilarious. Enjoy.

ARCHIVES / RSS
Blog

jQuery delayed observer usage example

h3  ~  30 Nov 2007, 03:16  –  post a comment

A reader asked me to post a simple usage example of my jQuery delayed observer,

so here it is:

$(document).ready(function(){

	$('input#adder').delayedObserver(0.5, function(value, object) {

		$('input#result').val() = value * 5;

	}

});

In this example the input with the id "result" will be updated by the value of the input with the id "adder" multiplied by 5 upon key up with a delay of 0.5 seconds.

A delayed observer can be useful in many cases, so far I've used it in two contexts:

  • I had to multiply the values of two fields upon keyup but if someone typed really fast it could screw the result, the delayed observer post-pone the equation until 0.5 seconds have elapsed without any keystroke, thus resolving my problem.
  • I've also used it for a Ajax auto complete on a field to prevent Ajax requests on each keystrokes.

post a comment Comments

no comments :|

Copyrighted stuff .. u know.