View Full Version : 30 seconds after initial event = do function. how to??
emehrkay
03-05-2006, 01:32 AM
i want to copy gmail's auto save feature. i want to say 30 or so seconds after an onchange event, for it to call another function. i dont know how to do a timed event though and i was thinking that since the event happens over and over again as the user types, the 30 seconds would be restarted with every keystroke.
how should i structure this?
thanks
arnyinc
03-05-2006, 01:43 AM
You can call the function onload with a 30 second delay. Then in the function you run the code and afterwards call itself with a 30 second delay.
<HTML>
<HEAD>
<TITLE>setTimeout example</TITLE>
<SCRIPT LANGUAGE="JavaScript">
function yourFunction(){
//Do your auto save stuff here
setTimeout("yourFunction()", 30000);
}
</SCRIPT>
</HEAD>
<BODY ONLOAD="setTimeout('yourFunction()', 30000);">
</BODY>
</HTML>
Kravvitz
03-05-2006, 02:28 AM
onchange is only triggered when the element looses focus after the value has changed, not each time the value is changed while the element still has focus.
emehrkay
03-05-2006, 02:41 AM
yeah you're right, i can use a keyup event or something like that. i think i found a timer though
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.