I'm implementing a auto save function based on the previous click button save function.

Now I basically use setTimeOut or setInterval to save a textarea input frequently. The user behavior should be: when the user type in, or do something else, then come back, the textarea input should be saved automatically (there is no limited timer for textarea input, therefore, no timer count down.pretty much like gmail auto save...) How much time will the user use is up to the user. After the user finishes the textarea input, they will click a button and trigger another event. I tried several suggestions, like change onClick to onBlur. But the users may a accidentally click outside of the textarea box and they don't want their input to be saved yet. Now I'm using setTimeOut, but I think it still can't implement fully what I wanted.

Here is my sample code:
in JS:
saveTxt ();
saveTxt () {
function content....
var textarea = document.getElementById('usrTxt');
sendTxt(textarea.value.substring(0, 500));
st = setTimeOut("saveTxt()", 5000);
}

anotherEvent() {
content....
clearTimeOut(st);
}

in HTML:
<textarea id="usrTxt".....>.....</textarea>
<input onclick="anotherEvent();"....>

But I'm wondering by using setTimeOut, how can the database be updated with the latest data which is the user's last input?

Got a seemingly simple jquery ajax solution like this online:
---------------------------------------------------------------------
var autosaveOn = false;
function myAutosavedTextbox_onTextChanged()
{
if (!autosaveOn)
{
autosaveOn = true;

$('#myAutosavedTextbox').everyTime("300000", function(){
$.ajax({
type: "POST",
url: "autosavecallbackurl",
data: "id=1",
success: function(msg) {
$('#autosavenotify').text(msg);
}
});
}
}
-------------------------------------------------
but not quite sure how I can apply this correctly to my implementation, esp. for the "url: autosavecallbackurl". My existing code was done previously by several others in dojo, extJS, etc. But the saveTxt() function works well with a button onClick. I need to remove the previous save button and make it auto save.

Any inputs/suggestions?

Thanks!