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 </strong></td>
<td align="center"><strong>Capacidad </strong></td>
</tr>
<tr>
<td align="center"><input type="text" name="consumo" size="15"> </td>
<td align="center"><input type="text" name="capacidad" size="15"> </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 </strong></td>
<td align="center"><strong>Capacidad </strong></td>
</tr>
<tr>
<td align="center"><input type="text" name="consumo[]" size="15"> </td>
<td align="center"><input type="text" name="capacidad[]" size="15"> </td>
</td>
</table><br><br>
<input type="submit" value="Siguiente" name="validar">
</form>
</body>
</html>