views:

22

answers:

1

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&iacute;vel.</p>")
    .hide()
    .fadeIn(1500, function() {
      $('#message').append("<img id='checkmark' />");
    });
  }
 });
return false;
});
})
A: 
<script type="text/javascript">
        $(document).ready(function () {

        $("#submit").validate({
                                rules:{
                                        textarea_name:{
                                                required:true,
                                                minlength:8
                                                }
                                      }
                               });
                           });
</script>
klox
Hi, Thank you for your comment.The code I wrote above is correct.It was a problem with the browser cache and not carried to function properly.He was trying to validate all fields on a form.Thanks
Rey