Guest User

Javascript

a guest
Aug 9th, 2013
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $(document).ready(function(){
  2.  
  3.         $('#contact_form').submit(function(event){
  4.  
  5.             /* stop form from submitting normally */
  6.             event.preventDefault();
  7.  
  8.             // Variable declaration
  9.             var name = $('#name').val();   
  10.             var email = $('#email').val();
  11.             var subject = $('#subject').val();
  12.             var message = $('#message').val();
  13.            
  14.            // Disable submit button just after the form processed 1st time successfully.
  15.             $('#submit').attr({'disabled' : 'true', 'value' : 'Sending...' });
  16.            
  17.             /* Post Ajax function of jQuery to get all the data from the submission of the form as soon as the form sends the values to email.php*/
  18.             $.post("php/function/email.php", $("#contact_form").serialize(),function(result){
  19.                 //Check the result set from email.php file.
  20.                 if(result == 'sent'){  
  21.                     //If the email is sent successfully, remove the submit button
  22.                      $('#submit').remove();
  23.                     //Display the success message
  24.                     $('#success').fadeIn(500);
  25.                 }else{
  26.                     //Display the error message
  27.                     $('#error').fadeIn(500);
  28.                     // Enable the submit button again
  29.                     $('#submit').removeAttr('disabled').attr('value', 'Send Message');
  30.                 }
  31.             });
  32.             }
  33.         });    
  34.     );
Advertisement
Add Comment
Please, Sign In to add comment