Advertisement
Guest User

Untitled

a guest
Apr 14th, 2012
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $(document).ready(function() {
  2.  
  3.   //al click sul bottone del form
  4.   $("#bottone").click(function(){
  5.      
  6.      var timer = 2000;
  7.  
  8.     //associo variabili generali
  9.     var nome = $("#nome").val();
  10.     var email = $("#email").val();
  11.     var oggetto = $("#oggetto").val();
  12.     var messaggio = $("#messaggio").val();
  13.  
  14.     //inizio controllo campi obbligatori   
  15.     if  (nome == "" || email == "" || oggetto == "")  {
  16.  
  17.            
  18.            
  19.             $("<div id='errori'></div>").appendTo("#ContactForm").html("<img src='alert-icon.png' width='20' height='20' style='float:left;' /><span>Compila tutti i campi!</span>").delay(2000).fadeOut(timer);
  20.        
  21.        
  22.         } //se ci sono campi vuoti
  23.        
  24.         else { //se sono stati compilati tutti i campi
  25.  
  26.   //chiamata ajax
  27.     $.ajax({
  28.  
  29.       type: "POST",
  30.  
  31.       url: "engine.php",
  32.  
  33.     //il form invia i dati all'engine
  34.       data: "nome=" + nome + "&email=" + email + "&oggetto=" + oggetto  + "&messaggio=" + messaggio,
  35.       dataType: "html",
  36.  
  37.       success: function(msg)
  38.       {
  39.               $("<div id='risultato'></div>").appendTo("#ContactForm").html("<img src='mail-inviata.png' style='float:left;'  /><span>Email inviata con successo</span>").delay(2000).fadeOut(timer);
  40.       },
  41.      
  42.       error: function()
  43.       {
  44.         alert("Si e' verificato un errore imprevisto...");
  45.       }
  46.     });
  47.    
  48.         }//else
  49.  
  50.   });
  51.    
  52. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement