Automatically submitting a form with javascript – don’t break the back button!

There’s a problem with automatically submitting a form with javascript – by just calling the submit() method – you break the back button. We can use the fact that browsers remember form values to prevent this from happening.

<input type='hidden' id='submitted' name='submitted' value=''>
if (document.getElementById('submitted').value == '') {
document.getElementById('submitted').value = 'yes';

UPDATE: Forgot to test in IE. This doesn’t work in IE6 at least, but I could do with fixing the code so look for updates.

Leave a Reply