• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Form Resubmissions

 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
Does anyone know of some sample Javascript code
that will prevent form resubmissions. Remember
seeing an article somewhere but don't seem to
recall where I had seen it.
Thanks,
PJ
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How about this: instead of letting your form be submitted using an <INPUT TYPE=SUBMIT>, create a normal button with an event handler that does some stuff and then calls submit. Then you can have your function check for the existence of a cookie. If it finds the cookie, don't allow a resubmit. If it doesn't, then it writes the cookie and submits the form. Like this:

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I almost forgot. If you only want to prevent the user from resubmitting the form once each session, you can set some other value for the cookie but not the expiration date. That will cause the cookie to expire at the end of the browser session by default.
reply
    Bookmark Topic Watch Topic
  • New Topic