Ver Mensaje Individual
  #4 (permalink)  
Antiguo 14/09/2010, 20:26
Avatar de mayid
mayid
Colaborador
 
Fecha de Ingreso: marzo-2009
Ubicación: BsAs
Mensajes: 4.014
Antigüedad: 15 años, 1 mes
Puntos: 101
Respuesta: como se valida un textarea

No se por que lo de val() no funciona. O quizás haya algún otro error. Mi script para validar inputs y textareas es este:
Código javascript:
Ver original
  1. $(document).ready(function() {             
  2.    
  3.     respuestas =new Array();
  4.  
  5.     $("form input[name=guardar]").click(function(event)
  6.     {                  
  7.         $("span.incompleto").removeClass("incompleto");
  8.        
  9.         $("input, textarea").each(function(index) {
  10.            
  11.             if ($(this).val().length < 4 || $(this).val() == -1 || $(this).val() == '')
  12.             {
  13.                 respuestas[index] = false; 
  14.                 $(this).focus();       
  15.                 $(this).prev(".label").addClass("incompleto");
  16.             }
  17.             else   
  18.             {
  19.                 respuestas[index] = true;
  20.             }
  21.         });
  22.        
  23.         if ( $.inArray(false, respuestas) != -1)
  24.         {          
  25.             $(".mensaje").text("Te falta completar datos.").css("display", "block");;
  26.             return false;  
  27.         }  
  28.         else
  29.         {
  30.             $(".mensaje").addClass("enviando").text("Enviando...");
  31.             return true;
  32.         }  
  33.     });
  34.  
  35. });