Validate form and output message : Form Submit « jQuery « JavaScript Tutorial






<html>
  <head>
    <script type="text/javascript" src="js/jquery-1.3.2.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
        
            $("form").submit(function() {
              if ($("input:first").val() == "asdf") {
                $("span").text("Validated...").show();
                return true;
              }
              $("span").text("Not valid!").show().fadeOut(1000);
              return false;
            });
        });
    </script>

  </head>
  <body>
    <body>
          <form action="javascript:alert('success!');">
              <input type="text" />
              <input type="submit" />
          </form>
          <span></span>
    </body>
</html>








30.125.Form Submit
30.125.1.Cancel submit event by returning false
30.125.2.Turn off submit action
30.125.3.Submit event
30.125.4.To trigger the submit event on the first form on the page
30.125.5.Validate form and output message