1

I'm using jQuery's submit() method to do some basic form validation before the user is sent to the next page

$(document).ready(function(){
    $("form").submit(function() {
        // form validation, set errors_detected = true on errors

        if(errors_detected)
        {
            alert("error");
            return false;
        }   
    });
});

The problem is that if the user has passed the validation and clicks the Back button in the browser, the jquery code stops working. I'm using Opera.

BaUn
  • 159
  • 3
  • 9
  • What browser is this happening on or is it all? – Andy Rose Nov 02 '11 at 09:20
  • 1
    Read this link. Might help you : http://stackoverflow.com/questions/158319/cross-browser-onload-event-and-the-back-button – Rohan Nov 02 '11 at 09:22
  • Rohan, have check the solutions offered and it does not work. But at least the problem - browser caching - is identified. – BaUn Nov 02 '11 at 09:32

1 Answers1

0

Because usually when the user hits the back button, the browser shows the cached copy of the page, and doesn't run the $(document).ready() stuff again, AFAIK.

Not sure of the best way around this. Maybe setting a no-cache header?

GregL
  • 37,147
  • 8
  • 62
  • 67
  • Setting no-cache header using php didn't work either. Maybe this is Opera only bug. – BaUn Nov 02 '11 at 09:42
  • Yes, this is an Opera 11.52 bug. Tried it in Chrome 15.x and everything works as intended. – BaUn Nov 02 '11 at 09:44