JSFiddle - React, Tailwind, and code Playground
by tanoloco
HTML
enter something here<br>
<input type="text" name="name" id="name" title="name" value="" class="input-text" />
<br>
<br>
here the new value will be entered:<br>
<input type="text" name="second" id="second" title="second" value="" class="input-text" />
JavaScript
window.timeouts = new Array();
window.memo_values = new Array();
function onChangeValue(callback)
{
if (this.value != window.memo_values[this.id])
{
window.memo_values[this.id] = this.value;
if (callback instanceof Function)
{
callback.call(this);
}
else
{
eval( callback );
}
}
}
function doSomething()
{
// for example
jQuery('#second').val(this.value);
}
jQuery('#name').focus(function ()
{
var id = jQuery(this).attr('id');
window.timeouts[id] = setInterval('onChangeValue.call(document.getElementById("'+ id +'"), doSomething)', 500);
});
jQuery('#name').blur(function ()
{
var id = jQuery(this).attr('id');
onChangeValue.call(document.getElementById(id), doSomething);
clearInterval(window.timeouts[id]);
delete window.timeouts[id];
});