Ver Mensaje Individual
  #6 (permalink)  
Antiguo 07/01/2009, 09:59
warbandit69
 
Fecha de Ingreso: diciembre-2008
Ubicación: http://www.solucionesrios.tk/
Mensajes: 413
Antigüedad: 16 años, 2 meses
Puntos: 19
Respuesta: Soy novato en JS me podran ayudar con esto por favor

Cita:
Iniciado por marcopoloaz06 Ver Mensaje
Código javascript:
Ver original
  1. var ubicacion2, ubicacion;
  2. onload = function(){
  3.     ubicacion = document.getElementById("ubicacion");
  4.     ubicacion2 = document.getElementById("ubicacion2");
  5. };
  6.  
  7. function valida(){
  8.     if( ubicacion.selectedIndex == 3 ){
  9.         var empty = notEmpty(ubicacion2,"Por favor ingrese alguna ubicacion");
  10.         if( !empty )return empty;
  11.     }
  12.    
  13.     return true;
  14. }
  15.  
  16. function notEmpty(elem, helperMsg)
  17. {
  18.     if( !(/\s*[^\s]+\s*/.test(elem.value)) )
  19.     {
  20.         alert(helperMsg);
  21.         elem.focus(); // Devuelvo al usuario al input
  22.         return false;
  23.     }
  24.     return true;
  25. }
Hola amigo gracias pero sucede que tengo varios if anidados son demasiado largos, por lo que no se donde poner esa funcion, te voy a pegar el codigo sin las funciones adicionales para que veas:

Código javascript:
Ver original
  1. <script language="javascript" type="text/javascript">
  2.  
  3. function formValidator(){
  4. // Make quick references to our fields
  5. var serialemp = document.getElementById("serial1");
  6. var serial = document.getElementById("serial2");
  7. var descripcion = document.getElementById("descripcion");
  8. var proveedor = document.getElementById("proveedor");
  9. var ubicacion = document.getElementById("ubicacion");
  10. var ubicacion2 = document.getElementById("ubicacion2");
  11. var factura = document.getElementById("factura");
  12. var cantidad = document.getElementById("cantidad");
  13. var precio = document.getElementById("precio");
  14. var adq_dia = document.getElementById("adq_dia");
  15. var adq_mes = document.getElementById("adq_mes");
  16. var adq_ano = document.getElementById("adq_ano");
  17. var gar_dia = document.getElementById("gar_dia");
  18. var gar_mes = document.getElementById("gar_mes");
  19. var gar_ano = document.getElementById("gar_ano");
  20. var estado = document.getElementById("estado");
  21. var ci_responsable = document.getElementById("ci_responsable");
  22. var ci_usuario = document.getElementById("ci_usuario");
  23.  
  24. // Check each input in the order that it appears in the form!
  25. if(notEmpty(serialemp,"Por favor ingrese algun serial") && isNumeric(serialemp,"Por favor sólo ingrese números para los seriales empresariales")){
  26.     if(notEmpty(serial,"Por favor ingrese el serial del articulo, de no tener escriba N/A")){
  27.         if(notEmpty(descripcion,"Por favor ingrese alguna descripción")){
  28.             if(madeSelectionproveedor(proveedor,"Por favor seleccione un proveedor del(de los) artículo(s)")){
  29.                 if(madeSelectionubicacion(ubicacion,"Por favor seleccione una ubicación del(de los) artículo(s)")){
  30.                     if (valida(ubicacion2,"Por favor ingrese alguna ubicación")){
  31.                     if(notEmpty(factura,"Por favor ingrese algun número de fáctura") && isAlphanumeric(factura,"Por favor sólo ingrese números y/o letras para la factura (sin espacios en blanco)")){     
  32.                         if(notEmpty(cantidad,"Por favor ingrese la cantidad de artículos") && isNumeric(cantidad,"Por favor sólo ingrese números para la cantidad")){                  
  33.                                 if(notEmpty(precio,"Por favor ingrese el precio del(de los) artículo(s)") && isNumeric(precio, "Por favor sólo ingrese números para el precio")){
  34.                                
  35.                                         if(madeSelectiondia(adq_dia,"Por favor seleccione el día de adquisición")){
  36.                                                 if(madeSelectionmes(adq_mes,"Por favor seleccione el mes de adquisición")){
  37.                                                     if(madeSelectionano(adq_ano,"Por favor seleccione el año de adquisición")){
  38.                                                         if(madeSelectiondia1(gar_dia,"Por favor seleccione el día de vencimiento de la garantía")){
  39.                                                             if(madeSelectionmes1(gar_mes,"Por favor seleccione el mes de vencimiento de la garantía")){
  40.                                                                 if(madeSelectionano1(gar_ano,"Por favor seleccione el año de vencimiento de la garantía")){
  41.                                                                     if(madeSelectionestado(estado,"Por favor seleccione el estado del artículo")){
  42.                                                                         if(madeSelectionresponsable(ci_responsable,"Por favor seleccione el usuario del artículo")){
  43.                                                                             if(madeSelectionusuario(ci_usuario,"Por favor seleccione el encargado (responsable) del artículo")){
  44.                                                                                 return true;
  45.                                                                             }
  46.                                                                         }
  47.                                                                     }
  48.                                                                 }
  49.                                                             }
  50.                                                         }
  51.                                                     }
  52.                                                 }
  53.                                             }
  54.                                         }
  55.                                     }
  56.                                 }
  57.                             }
  58.                         }
  59.                     }
  60.                 }
  61.             }
  62.         }
  63.        
  64. return false;
  65. }

y continuan las funciones hasta el tag </script>

y esa verificacion debo ponerla dentro de esos if anidados (que son bastantes por cierto) :S