Ver Mensaje Individual
  #1 (permalink)  
Antiguo 11/12/2008, 07:58
Jahir
 
Fecha de Ingreso: abril-2008
Mensajes: 28
Antigüedad: 16 años, 10 meses
Puntos: 0
validar input text dinamicos

Buenos dias he tratado de realizar validaciones de los text dinamicos pero no se porque no salen alguno me podria decir cual ha sido mi error
Código HTML:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script language="javascript" script type="text/javascript">
function vacio(q)
{  
   for ( i = 0; i < q.length; i++ )
	{ 
	   if ( q.charAt(i) != " " )
	   { 
			   return true 
	   } 
   } 
	return false 
}
var edad= <? echo $edad ?>;
//funcion que me recoge cada input del formulario
function validacion(formulario)
{ 
	for (i=1; i<=edad; i++)
	{ 
		if (vacio(formulario.consumo+i.value) == false)
		{
			alert('Campo de consumo vacio')
			return false
		}
		if(isNaN(formulario.consumo+i.value))
		{
			alert("Debe ingresar solo numeros")
			return false
		}
		if (vacio(formulario.capacidad+i.value) == false)
		{
			alert('Campo de capacidad vacio')
			return false
		}
		if(isNaN(formulario.capacidad+i.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">
			<?
			for ($i=1; $i<=$edad; $i++)
			{
			?>
			<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="<? echo "consumo".$i;?>" size="15">&nbsp;</td>
			<td align="center"><input type="text" name="<? echo "capacidad".$i;?>" size="15">&nbsp;</td>
			</td>
			<?
			}
			?>			
			</table><br><br>
			<input type="submit" value="Siguiente" name="validar">
</form>
</body>
</html>