Foros del Web » Programando para Internet » Javascript »

validar input text dinamicos

Estas en el tema de validar input text dinamicos en el foro de Javascript en Foros del Web. Buenas tardes. quisiera saber como validar input text dinamicos Código HTML: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content= "text/html; ...
  #1 (permalink)  
Antiguo 10/12/2008, 13:50
 
Fecha de Ingreso: abril-2008
Mensajes: 28
Antigüedad: 16 años
Puntos: 0
validar input text dinamicos

Buenas tardes.

quisiera saber como validar input text dinamicos
Código HTML:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script language="javascript" type="text/javascript">
        //funcion para validar que el campo no este vacio
        function vacio(q) {  
           for ( i = 0; i < q.length; i++ )
		    { 
               if ( q.charAt(i) != " " )
			   { 
                       return true 
               } 
           } 
            return false 
        }
        //funcion que me recoge cada input del formulario
        function validacion(formulario)
		{ 
            if (vacio(formulario.consumo.value) == false)
			{
                alert('Campo de consumo vacio')
                return false
            }
            if(isNaN(formulario.consumo.value))
			{
                alert("Debe ingresar solo numeros")
                return false
            }
		    if (vacio(formulario.capacidad.value) == false)
			{
                alert('Campo de capacidad vacio')
                return false
            }
            if(isNaN(formulario.capacidad.value))
			{
                alert("Debe ingresar solo numeros")
                return false
            }
        return true
        }
    </script>
</head>
<body>
<font color="#00FF66" face="Maiandra GD"><h5><div align="right">Usuario Activo :<? echo $_SESSION["Nombre"]." ".$_SESSION["Apellido"]?></div></h5></font>
			<form action="untitled1.php" method="post"  onsubmit="return validacion(this)">
			<table width="50%" border="1" cellpadding="2" cellspacing="2" bgcolor="#000099">
			<tr>
			<td align="center"><strong>Consumo &nbsp;</strong></td>
			<td align="center"><strong>Capacidad &nbsp;</strong></td>
			</tr>
			<tr>
			<td align="center"><input type="text" name="consumo" size="15">&nbsp;</td>
			<td align="center"><input type="text" name="capacidad" size="15">&nbsp;</td>
			</td>			
			</table><br><br>
			<input type="submit" value="Siguiente" name="validar">
</form>
</body>
</html> 
Esta es la validacion de un solo input text pero aun no he podido validar mas de un input este es el codigo que he pensado para hacer la validacion de mas de uno alguno de ustedes me podria colaborar con esto
Código HTML:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script language="javascript" type="text/javascript">
        //funcion para validar que el campo no este vacio
        function vacio(q) {  
           for ( i = 0; i < q.length; i++ )
		    { 
               if ( q.charAt(i) != " " )
			   { 
                       return true 
               } 
           } 
            return false 
        }
        //funcion que me recoge cada input del formulario
        function validacion(formulario)
		{ 
            if (vacio(formulario.consumo[].value) == false)
			{
                alert('Campo de consumo vacio')
                return false
            }
            if(isNaN(formulario.consumo[].value))
			{
                alert("Debe ingresar solo numeros")
                return false
            }
		    if (vacio(formulario.capacidad[].value) == false)
			{
                alert('Campo de capacidad vacio')
                return false
            }
            if(isNaN(formulario.capacidad[].value))
			{
                alert("Debe ingresar solo numeros")
                return false
            }
        return true
        }
    </script>
</head>
<body>
<font color="#00FF66" face="Maiandra GD"><h5><div align="right">Usuario Activo :<? echo $_SESSION["Nombre"]." ".$_SESSION["Apellido"]?></div></h5></font>
			<form action="untitled1.php" method="post"  onsubmit="return validacion(this)">
			<table width="50%" border="1" cellpadding="2" cellspacing="2" bgcolor="#000099">
			<tr>
			<td align="center"><strong>Consumo &nbsp;</strong></td>
			<td align="center"><strong>Capacidad &nbsp;</strong></td>
			</tr>
			<tr>
			<td align="center"><input type="text" name="consumo[]" size="15">&nbsp;</td>
			<td align="center"><input type="text" name="capacidad[]" size="15">&nbsp;</td>
			</td>			
			</table><br><br>
			<input type="submit" value="Siguiente" name="validar">
</form>
</body>
			</html> 
  #2 (permalink)  
Antiguo 10/12/2008, 13:56
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 18 años
Puntos: 2135
Respuesta: validar input text dinamicos

Tema trasladado a Javascript.
  #3 (permalink)  
Antiguo 10/12/2008, 14:25
 
Fecha de Ingreso: abril-2008
Mensajes: 28
Antigüedad: 16 años
Puntos: 0
Respuesta: validar input text dinamicos

No se por que no me valida todos los campos
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 05:49.