1 Example(s) of JQuery Form


Description :

In this example the submit() method triggers the submit event, or attaches a function to run when a submit event occurs.


JQuery Form Example - 1
<!doctype html>
<html>
<head>
  <style>
  p {
    margin: 0;
    color: blue;
  }
  div,p {
    margin-left: 10px;
  }
  span {
    color: red;
  }
  </style>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
</head>
<body>
 
<p style="font-size: 25px">Type correct to validate.</p><br>
<form action="javascript:alert( 'success!' );">
  <div>
    <input type="text">
    <input type="submit">
  </div>
</form>
<span></span>
 
<script>
$( "form" ).submit(function( event ) {
  if ( $( "input:first" ).val() === "correct" ) {
    $( "span" ).text( "Validated..." ).show();
    return;
  }
 
  $( "span" ).text( "valid data!" ).show().fadeOut( 3000 );
//   event.preventDefault();
});
</script>
</body>
</html>

Output