Hello!
i'm trying validate a form (all fields) with jQuery
My code is valid only for the input area, but it's don't works for the <textarea>
, anybody knows how i can fix this problem?
$(".button").click(function() {
// validate and process form
// first hide any error messages
$('.error').hide();
var name = $("input#name").val();
if (name == "") {
$("label#name_error").show();
$("input#name").focus();
return false;
}
var email = $("input#email").val();
if (email == "") {
$("label#email_error").show();
$("input#email").focus();
return false;
}
var subject = $("input#subject").val();
if (subject == "") {
$("label#subject_error").show();
$("input#subject").focus();
return false;
}
var message = $("textarea#message").val();
if (message == "") {
$("label#message_error").show();
$("textarea#message").focus();
return false;
}
var dataString = 'name='+ name + '&email=' + email + '&subject=' + subject + '&message=' + message;
//alert (dataString);return false;
$.ajax({
type: "POST",
url: "bin/process.php",
data: dataString,
success: function() {
$('#contact_form').html("<div id='message'></div>");
$('#message').html("<h2>Mensagem enviada com sucesso!</h2>")
.append("<p>Entraremos em contato assim que possível.</p>")
.hide()
.fadeIn(1500, function() {
$('#message').append("<img id='checkmark' />");
});
}
});
return false;
});
})