You can add a handler onsubmit
. Without using a third party library like jQuery, here's a basic way to do it with inline JavaScript:
<form onsubmit="document.getElementById('first').style.display = 'none';document.getElementById('second').style.display = '';">
onsubmit
is triggered whenever the form is submitted, whether by clicking a button Submit
, programmatically, or if the user clicks Enterin a text box, for example.
However, I would recommend using jQuery and a more unobtrusive approach than this built-in approach. If you want to see how to do this using jQuery, here's a jsFiddle that shows one way to accomplish this. Basically, you would add id
, for example myform
, to an element form
, and then add this to your JavaScript:
$(document).ready(function() {
$("#myform").submit(function(e) {
$("#first").hide();
$("#second").show();
});
});
source
to share