37 lines
1.2 KiB
JavaScript
37 lines
1.2 KiB
JavaScript
|
// JavaScript Document
|
||
|
|
||
|
// contact form
|
||
|
$(document).ready(function() {
|
||
|
$('form#form').submit(function() {
|
||
|
$('form#form .error').remove();
|
||
|
var hasError = false;
|
||
|
$('.requiredField').each(function() {
|
||
|
if(jQuery.trim($(this).val()) == '') {
|
||
|
var labelText = $(this).prev('label').text();
|
||
|
$(this).parent().append('<span class="error">You forgot to enter your '+labelText+'</span>');
|
||
|
$(this).addClass('inputError');
|
||
|
hasError = true;
|
||
|
} else if($(this).hasClass('email')) {
|
||
|
var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
|
||
|
if(!emailReg.test(jQuery.trim($(this).val()))) {
|
||
|
var labelText = $(this).prev('label').text();
|
||
|
$(this).parent().append('<span class="error">You entered an invalid '+labelText+'</span>');
|
||
|
$(this).addClass('inputError');
|
||
|
hasError = true;
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
if(!hasError) {
|
||
|
$('form#form input.submit').fadeOut('normal', function() {
|
||
|
$(this).parent().append('');
|
||
|
});
|
||
|
var formInput = $(this).serialize();
|
||
|
$.post($(this).attr('action'),formInput, function(data){
|
||
|
$('form#form').slideUp("fast", function() {
|
||
|
$(this).before('<div class="success">Thank you. Your email was sent successfully.</div>');
|
||
|
});
|
||
|
});
|
||
|
}
|
||
|
return false;
|
||
|
});
|
||
|
});
|