jQuery Form How to - Submit form and replace submit button with progress indicator








Question

We would like to know how to submit form and replace submit button with progress indicator.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.8.3.js'></script>
<style type='text/css'>
form {<!--from w w  w.  j a  va  2s.  c  o m-->
  display: inline-block;
}
</style>
<script type='text/javascript'>
$(window).load(function(){
    $('form').on('submit', function(e){
        var submitButton = $(this).find('input[type=submit]');
        $(this).append('<span>submitting...</span>');
        submitButton.css('display', 'none');
    });
});
</script>
</head>
<body>
  <form action="#" method="post" target="_blank">
    <input type="text" name="name" value="value"> <input
      id="submitButton" type="submit" value="Submit the form">
  </form>
</body>
</html>

The code above is rendered as follows: