1

i have a jsp page which contains 2 forms as follows:

<form action=cancelRide.html id="cancel" method="get">
    <button type="submit" name="cancel">Cancel</button>
</form>
<form action=confirmRide.html method="post">
    <button type="submit" name="book">Book</button>
</form>

And on the click of cancel button it goes to cancelRide controller.I need the same thing to happen when the back button of the browser clicked .That is when the back button is clicked I need the cancelRide form to be submitted.

Manikanta Mani
  • 105
  • 2
  • 7
  • I know jquery mobile has a navigate event but I don't think regular jquery does: http://api.jquerymobile.com/navigate/ – AtheistP3ace Nov 16 '15 at 14:42
  • 1
    a back button on your browser? or a back button on your page that you coded? – indubitablee Nov 16 '15 at 14:47
  • 2
    You might want to start with this page http://stackoverflow.com/questions/25806608/how-to-detect-browser-back-button-event-cross-browser – Johan Nov 16 '15 at 14:47
  • And this one can help as well: http://stackoverflow.com/questions/17594413/js-or-jquery-browser-back-button-click-detector – Magicprog.fr Nov 16 '15 at 14:50

1 Answers1

0

Try

   $( "#back" ).click(function() {
      $( this ).parent().submit();
    });

if the back button is right inside the form as in your example or

$( "#back" ).click(function() {
  $( "#back_form" ).submit();
});

otherwise.

Maksim
  • 91
  • 1
  • 8