I want to write a code that behaves like google's translate form.
When I enter a letter in the input text-box, there is a 0.5
second delay that waits for new input. If no new input is received, the request is sent to the server which will return the results on an output text-box.
I wrote something, but it is not complete. Could you help me?!
$(document).ready(function(){
$('#source').keyup(function(){
var keyUpTime = $.now();
setTimeout(function(){
if($.now() - keyUpTime >= 500) {
sendValue($('#source').val());
}
},500);
});
});
function sendValue(str){
$.post("ajax.php",{ sendValue: str }, function(data){
$('#result_box').html(data.returnValue);
}, "json");
};