$(document).ready(function(){ $('#success, #errors').hide(); $('a.vastaa').click(function(){ $('#vastaa').show(); scroll(0,300); }); // close the modal window is close div or mask div are clicked. $('.close').click(function() { $('div#vastaa').stop().hide('slow'); }); $('#laheta').click(function() { // we want to store the values from the form input box, then send via ajax below $('#errors').empty(); var error_count; error_count = 0; var nimi = $('#nimi').val(); var vastaanottaja = $('#vastaanottaja').val(); var email = $('#email').val(); var otsikko = $('#otsikko').val(); var viesti = $('#viesti').val(); // Tyhjä viesti if(nimi == '') { $('#errors').append('

Nimi puuttuu.

'); error_count += 1; } // Tyhjä viesti if(email == '') { $('#errors').append('

Sähköpostiosoite puuttuu

'); error_count += 1; } // Tyhjä viesti if(otsikko == '') { $('#errors').append('

Otsikko puuttuu

'); error_count += 1; } // Tyhjä viesti if(viesti == '') { $('#errors').append('

Kommentti puuttuu.

'); error_count += 1; } //No Errors? if(error_count === 0) { $.ajax({ type: "POST", url: "/inc/send.php", data: "to=" + vastaanottaja + "&name=" + nimi + "&subject=" + otsikko + "&email=" + email + "&comment=" + viesti, success: function() { $('#success').fadeIn(); } }); } else { $('#errors').show(); } return false; }); });