Cita:
Iniciado por marcopoloaz06
Código javascript
:
Ver originalvar ubicacion2, ubicacion;
onload = function(){
ubicacion = document.getElementById("ubicacion");
ubicacion2 = document.getElementById("ubicacion2");
};
function valida(){
if( ubicacion.selectedIndex == 3 ){
var empty = notEmpty(ubicacion2,"Por favor ingrese alguna ubicacion");
if( !empty )return empty;
}
return true;
}
function notEmpty(elem, helperMsg)
{
if( !(/\s*[^\s]+\s*/.test(elem.value)) )
{
alert(helperMsg);
elem.focus(); // Devuelvo al usuario al input
return false;
}
return true;
}
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<script language="javascript" type="text/javascript">
function formValidator(){
// Make quick references to our fields
var serialemp = document.getElementById("serial1");
var serial = document.getElementById("serial2");
var descripcion = document.getElementById("descripcion");
var proveedor = document.getElementById("proveedor");
var ubicacion = document.getElementById("ubicacion");
var ubicacion2 = document.getElementById("ubicacion2");
var factura = document.getElementById("factura");
var cantidad = document.getElementById("cantidad");
var precio = document.getElementById("precio");
var adq_dia = document.getElementById("adq_dia");
var adq_mes = document.getElementById("adq_mes");
var adq_ano = document.getElementById("adq_ano");
var gar_dia = document.getElementById("gar_dia");
var gar_mes = document.getElementById("gar_mes");
var gar_ano = document.getElementById("gar_ano");
var estado = document.getElementById("estado");
var ci_responsable = document.getElementById("ci_responsable");
var ci_usuario = document.getElementById("ci_usuario");
// Check each input in the order that it appears in the form!
if(notEmpty(serialemp,"Por favor ingrese algun serial") && isNumeric(serialemp,"Por favor sólo ingrese números para los seriales empresariales")){
if(notEmpty(serial,"Por favor ingrese el serial del articulo, de no tener escriba N/A")){
if(notEmpty(descripcion,"Por favor ingrese alguna descripción")){
if(madeSelectionproveedor(proveedor,"Por favor seleccione un proveedor del(de los) artículo(s)")){
if(madeSelectionubicacion(ubicacion,"Por favor seleccione una ubicación del(de los) artículo(s)")){
if (valida(ubicacion2,"Por favor ingrese alguna ubicación")){
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)")){
if(notEmpty(cantidad,"Por favor ingrese la cantidad de artículos") && isNumeric(cantidad,"Por favor sólo ingrese números para la cantidad")){
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")){
if(madeSelectiondia(adq_dia,"Por favor seleccione el día de adquisición")){
if(madeSelectionmes(adq_mes,"Por favor seleccione el mes de adquisición")){
if(madeSelectionano(adq_ano,"Por favor seleccione el año de adquisición")){
if(madeSelectiondia1(gar_dia,"Por favor seleccione el día de vencimiento de la garantía")){
if(madeSelectionmes1(gar_mes,"Por favor seleccione el mes de vencimiento de la garantía")){
if(madeSelectionano1(gar_ano,"Por favor seleccione el año de vencimiento de la garantía")){
if(madeSelectionestado(estado,"Por favor seleccione el estado del artículo")){
if(madeSelectionresponsable(ci_responsable,"Por favor seleccione el usuario del artículo")){
if(madeSelectionusuario(ci_usuario,"Por favor seleccione el encargado (responsable) del artículo")){
return true;
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
return false;
}
y continuan las funciones hasta el tag </script>
y esa verificacion debo ponerla dentro de esos if anidados (que son bastantes por cierto) :S