Foros del Web » Programando para Internet » Javascript »

Verificar si un campo esta activo y si esta como verificar que no este vacio

Estas en el tema de Verificar si un campo esta activo y si esta como verificar que no este vacio en el foro de Javascript en Foros del Web. Hola, gracias por leer mi nota tengo un problemilla a la hora de verificar un formulario, tengo un campo de texto desactivado (input disabled) en ...
  #1 (permalink)  
Antiguo 01/01/2009, 15:17
 
Fecha de Ingreso: diciembre-2008
Ubicación: http://www.solucionesrios.tk/
Mensajes: 413
Antigüedad: 15 años, 4 meses
Puntos: 19
Busqueda Verificar si un campo esta activo y si esta como verificar que no este vacio

Hola, gracias por leer mi nota tengo un problemilla a la hora de verificar un formulario, tengo un campo de texto desactivado (input disabled) en un formulario, que al activarlo debo verificar que no este vacio y al desactivarlo dejarlo pasar vacia la variable, pero con lo que tengo hecha nunca me deja pasar vacia la variable, ya este activo o desactivado el campo de texto. Me ayudan?

Codigo Javascript:

Código PHP:
<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(
notEmpty(ubicacion2,"Por favor ingrese alguna ubicacion")){ // he aqui la variable de los problemas
                        
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;

}

function 
notEmpty(elemhelperMsg)
{
    if(
elem.value.length == 0)
    {
        
alert(helperMsg);
        
elem.focus(); // Devuelvo al usuario al input
        
return false;
    }
    return 
true;
}



function 
isNumeric(elemhelperMsg)
{
    var 
numericExpression = /^[0-9]+$/;
    if(
elem.value.match(numericExpression))
    {
        return 
true;
    }
    else
    {
        
alert(helperMsg);
        
elem.focus();
        return 
false;
    }
}


function 
isAlphabet(elemhelperMsg)
{
    var 
alphaExp = /^[a-zA-Z]+$/;
    if(
elem.value.match(alphaExp))
    {
        return 
true;
    }
    else
    {
        
alert(helperMsg);
        
elem.focus();
        return 
false;
    }
}


function 
isAlphanumeric(elemhelperMsg)
{
    var 
alphaExp = /^[0-9a-zA-Z]+$/;
    if(
elem.value.match(alphaExp))
    {
        return 
true;
    }
    else
    {
        
alert(helperMsg);
        
elem.focus();
        return 
false;
    }
}


function 
madeSelectiondia(elemhelperMsg)
{
    if(
elem.value == "Día")
    {
        
alert(helperMsg);
        
elem.focus();
        return 
false;
    }
    else
    {
        return 
true;
    }
}

function 
madeSelectionmes(elemhelperMsg)
{
    if(
elem.value == "Mes")
    {
        
alert(helperMsg);
        
elem.focus();
        return 
false;
    }
    else
    {
        return 
true;
    }
}

function 
madeSelectionano(elemhelperMsg)
{
    if(
elem.value == "Año")
    {
        
alert(helperMsg);
        
elem.focus();
        return 
false;
    }
    else
    {
        return 
true;
    }
}

function 
madeSelectiondia1(elemhelperMsg)
{
    if(
elem.value == "Día")
    {
        
alert(helperMsg);
        
elem.focus();
        return 
false;
    }
    else
    {
        return 
true;
    }
}

function 
madeSelectionmes1(elemhelperMsg)
{
    if(
elem.value == "Mes")
    {
        
alert(helperMsg);
        
elem.focus();
        return 
false;
    }
    else
    {
        return 
true;
    }
}

function 
madeSelectionano1(elemhelperMsg)
{
    if(
elem.value == "Año")
    {
        
alert(helperMsg);
        
elem.focus();
        return 
false;
    }
    else
    {
        return 
true;
    }
}

function 
madeSelectionestado(elemhelperMsg)
{
    if(
elem.value == "Seleccione Estado")
    {
        
alert(helperMsg);
        
elem.focus();
        return 
false;
    }
    else
    {
        return 
true;
    }
}

function 
madeSelectionresponsable(elemhelperMsg)
{
    if(
elem.value == "Seleccionar Responsable por C.I.")
    {
        
alert(helperMsg);
        
elem.focus();
        return 
false;
    }
    else
    {
        return 
true;
    }
}

function 
madeSelectionusuario(elemhelperMsg)
{
    if(
elem.value == "Seleccionar Usuario por C.I.")
    {
        
alert(helperMsg);
        
elem.focus();
        return 
false;
    }
    else
    {
        return 
true;
    }
}

function 
madeSelectionubicacion(elemhelperMsg)
{
    if(
elem.value == "Seleccionar Ubicación")
    {
        
alert(helperMsg);
        
elem.focus();
        return 
false;
    }
    else
    {
        return 
true;
    }
}

function 
madeSelectionproveedor(elemhelperMsg)
{
    if(
elem.value == "Seleccione Proveedor")
    {
        
alert(helperMsg);
        
elem.focus();
        return 
false;
    }
    else
    {
        return 
true;
    }

Codigo PHP o parte de el:

Código PHP:
  <p>
    <
label><strong><br />
    <
br />
    
Ubicación</strong>
     <
select name="ubicacion" id="ubicacion" onchange="ubicacion2.disabled = this.value != 'Prestado/Otra Ubic.'">
      <
option>Seleccionar Ubicaci&oacute;n</option>
      <
option>Caracas</option>
      <
option>Maracaibo</option>
      <
option>Prestado/Otra Ubic.</option>
    </
select>
    </
label>
  </
p>
  <
p>&nbsp;</p>
  <
p>
    <
label><strong>Indicar Ubicaci&oacute;Personal</strong>
    <
input name="ubicacion2" type="text" id="ubicacion2" disabled="disabled"/>
    </
label
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 14:32.