JQuery delayedObserver plugin

Posted on January 6, 2010


I’ve never liked javascript programming. I’ve done some efforts, but found that its just as boring as it is hard.

Well, you can’t get around it, can you..?

I was fiddling with some ajax prototyping for a searchfield the other day. You know, the stupidly basic inputfield onchange=”callsomefunction()” stuff… Or was it onkeypress=”callsomefunction()”?

Luckily, a Stack Overflow question on this subject led me to JQuery Utils and the delayedObserver plugin.

Below a very simple example. An a delayedObserver callback function (“testfunction”) is set to the input field, with 1 second delay. This means that one second after finishing writing in the text field, the callback function (testfunction()) is executed. Simple and elegant!

<input type="text" id="input1" />

<script type="text/javascript">
                // Register the callback function with 1 sec delay
		$('input#input1').delayedObserver(testfunction, 1);
	// Callback function
        function testfunction(value, object) {

Thank you, haineault!

Tagged: ,
Posted in: JQuery