0

I am creating a form without a submit button that will send a submission every time a form element changes value. (All text inputs)

If I use onchange event the form won't submit until I blur the field, which would be too late. I need it to submit on each minor change. E.g. typing "five" would mean 5 submits.

If i use key up it will make a lot of submissions and create a race condition on the server. What is the best method of doing this? Are there any other options?

gillyspy
  • 1,578
  • 8
  • 14
Chris Muench
  • 17,444
  • 70
  • 209
  • 362
  • So you want to send ajax submit requests on every input change to the server without sending too many submissions? I don't see why you would want to do that in the first place. – Farhan Ahmad Dec 07 '13 at 03:53
  • Why would you want to submit the form (with many inputs) each time any input changes? If you can provide a reason, we may come up with a hack! – dlock Dec 07 '13 at 03:53
  • if you are trying to track every single little change (i.e. keypress) then you could have a key based handler cache those changes and have it submit every X milliseconds or so. You can wrap your request with an interval timer. Perhaps even have a handler on blur that trumps the interval and does a full submit. By the way if you wrap your requests in a reasonable interval then if the timer is a reasonable length then your fears of a race condition are greatly allays as the timer has a more linear timer queue than ajax requests do. – gillyspy Dec 07 '13 at 03:56
  • The idea is, I will have a page of 25 forms that update data for a particular item. I don't want the user to remember to hit submit each time and I don't want a page refresh. I want behavior similar to google docs – Chris Muench Dec 07 '13 at 04:07

1 Answers1

0

google docs uses a timer, saves every 2 seconds or so. http://blog.benmcmahen.com/post/43174272622/auto-save-in-your-web-application

Other approaches to autosave exist, for example:

Community
  • 1
  • 1
actual_kangaroo
  • 5,971
  • 2
  • 31
  • 45
  • If I have a timer on let's say 20 forms, this could be a lot of requests at once. Do you think I should keep a list of the forms that actually have been edited and sync these only every 2 seconds? I don't want to do a push service – Chris Muench Dec 07 '13 at 06:24
  • You would save all forms at once, so once every 2s total. You can do a client side check to see which fields have changed and then save only those fields. – actual_kangaroo Dec 07 '13 at 06:54
  • Wouldn't 25 ajax requests be a lot for the server to handle? – Chris Muench Dec 07 '13 at 16:45
  • your right, that idea aout keeping a list of changed forms should help – actual_kangaroo Dec 08 '13 at 06:16