form validation in jquery with ajax


$(document).ready(function(e) {
$("#contact-submit").on('click',function(){
var error = false;
if($("#name").val()==''){
$("#name").addClass('error');
error = true;
return false;
}
if($("#phone").val()==''){
$("#phone").addClass('error');
error = true;
return false;
}

if($("#email").val()==''){
$("#email").addClass('error');
error = true;
return false;
}
if(!IsEmail($("#email").val())){
$("#email").addClass('error');
error = true;
return false;
}

if(error){
$('.message').html('

!Information submission error. Please contact website administrator.

');
return false;
}else{
$.ajax({
data: $("#contact-form").serialize(),
url:"inc/sendmail.php",
method:"POST",
beforeSend: function() {
$('.message').html('

');
}
})
.done(function(msg) {
if(msg=='1'){
$('.message').html('

Thank you for providing your Contact Information.
One of our executive will contact you soon.!!

');
$("#loader").hide();
$("#contact-form input[type=text],textarea").each(function(){
$(this).val('');
});
}
else
$('.message').html('

!Contact Information submission error. Please contact website administrator.

');
});
//return true;
}

});

$("#contact-form input[type=text],textarea").focus(function(){
if($(this).hasClass('error')){
$(this).removeClass('error');
return false;
}
});
function IsEmail(email) {
var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
return regex.test(email);
}

/**************************Resume Form*****************************/

$("#resume-submit").on('click',function(){

var error = false;
if($("#name").val()==''){
$("#name").addClass('error');
error = true;
return false;
}

if(!IsEmail($("#email").val())){
$("#email").addClass('error');
error = true;
return false;
}

if($("#professional").val()==''){
$("#professional").addClass('error');
error = true;
return false;
}

if($("#location").val()==''){
$("#location").addClass('error');
error = true;
return false;
}

/*if($("#category").val()==''){
$("#category").addClass('error');
error = true;
return false;
}*/
if($("#description").val()==''){
$("#description").addClass('error');
error = true;
return false;
}

if(error){
$('.message').html('

!Information submission error. Please contact website administrator.

');
return false;
}else{
$("#resume-form").submit();
//$("form[name='resume-form']").submit();
}

});

$("#resume-form input[type=text],input[type=file],textarea,select").focus(function(){
if($(this).hasClass('error')){
$(this).removeClass('error');
return false;
}
});
function IsEmail(email) {
var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
return regex.test(email);
}

/*************** Jobs Search************/
$("#search").on('click',function(){
$.ajax({
data: $("#job-form").serialize(),
url:"inc/job-search.php",
method:"POST",
beforeSend: function() {
$('.jobs-message').html('

');
}
})
.done(function(msg) {
$('#jobs-result').html(msg);
$('.jobs-message').html('');
})

});

$('.add-more').click(function(){
var cid = $('#current').val();
var nextId = parseInt(cid);
$(this).before('

');
$('#current').val(nextId+1);
});

$(document).delegate('.remove','click',function(){
var did = $(this).attr('id');
alert(did);
$('#url_'+did).remove();
});

});

Advertisements