Autosave form every X seconds

Autosave form every X seconds

Hello All,

I'm trying to add auto-save functionality to my form. While I figured out 90% of the things of the overall functionality, I'm stuck at the most crucial one - triggering the ajax call when -

1. Any of the form field is updated. 

2. Ajax call is made every 10 second after the change is made. 

3. No ajax call is made when the fields are empty

I experimented with 

```
 $(":input").keypress(function() {
        setInterval(saveDraft(), 5000);
    });j

function saveDraft() { ... } 
```

However, that doesn't work as expected. Would really appreciate if someone could point me in the right direction. Thank you in advance.