How do I add animations (both in and out) for the tooltips here:
$('.requiredField').each(function () {
if ($.trim($(this).val()) == '') {
var labelText = $(this).prev('label').text();
$(this).parent().append('<div class="error">Please enter your ' + labelText + '!</div>');
$(this).addClass('inputError');
hasError = true;
} else if ($(this).hasClass('email')) {
var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,10})?$/;
if (!emailReg.test($.trim($(this).val()))) {
var labelText = $(this).prev('label').text();
$(this).parent().append('<div class="error">Sorry! You\'ve entered an invalid ' + labelText + '.</div>');
$(this).addClass('inputError');
hasError = true;
}
}
}
Also, how do I add animation to this banner that pops out, once the form has been submitted? Notice, the form has a fadeOut animation. I would also like to animate the paragraph with class=info
:
var formInput = $(this).serialize();
$.post($(this).attr('action'), formInput, function (data) {
$('form#contact-us').fadeOut("fast", function () {
$(this).before('<p class="info">Thanks! Your email has been submitted. Huzzah!</p>');
})
});
Script: http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js
<script type="text/javascript">
<!--//--><![CDATA[//><!--
$(document).ready(function() {
$('form#contact-us').submit(function() {
$('form#contact-us .error').remove();
var hasError = false;
$('.requiredField').each(function() {
if($.trim($(this).val()) == '') {
var labelText = $(this).prev('label').text();
$(this).parent().append('<div class="error">Please enter your '+labelText+'!</div>');
$(this).addClass('inputError');
hasError = true;
} else if($(this).hasClass('email')) {
var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,10})?$/;
if(!emailReg.test($.trim($(this).val()))) {
var labelText = $(this).prev('label').text();
$(this).parent().append('<div class="error">Sorry! You\'ve entered an invalid '+labelText+'.</div>');
$(this).addClass('inputError');
hasError = true;
}
}
});
if(!hasError) {
var formInput = $(this).serialize();
$.post($(this).attr('action'),formInput, function(data){
$('form#contact-us').fadeOut("fast", function() {
$(this).before('<p class="info">Thanks! Your email has been submitted. Huzzah!</p>');
});
});
}
return false;
});
});
//-->!]]>
</script>