JonneOpettaja

jQuery2

Nov 5th, 2018
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Submit the form via Ajax
  2.  
  3. function submitForm() {
  4.   var contactForm = $(this);
  5.  
  6.   // Are all the fields filled in?
  7.  
  8.   if ( !$('#senderName').val() || !$('#senderEmail').val() || !$('#message').val() ) {
  9.  
  10.     // No; display a warning message and return to the form
  11.     $('#incompleteMessage').fadeIn().delay(messageDelay).fadeOut();
  12.     contactForm.fadeOut().delay(messageDelay).fadeIn();
  13.  
  14.   } else {
  15.  
  16.     // Yes; submit the form to the PHP script via Ajax
  17.  
  18.     $('#sendingMessage').fadeIn();
  19.     contactForm.fadeOut();
  20.  
  21.     $.ajax( {
  22.       url: contactForm.attr( 'action' ) + "?ajax=true",
  23.       type: contactForm.attr( 'method' ),
  24.       data: contactForm.serialize(),
  25.       success: submitFinished
  26.     } );
  27.   }
  28.  
  29.   // Prevent the default form submission occurring
  30.   return false;
Advertisement
Add Comment
Please, Sign In to add comment