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 </strong></td> <td align="center"><strong>Capacidad </strong></td> </tr> <tr> <td align="center"><input type="text" name="<? echo "consumo".$i;?>" size="15"> </td> <td align="center"><input type="text" name="<? echo "capacidad".$i;?>" size="15"> </td> </td> <? } ?> </table><br><br> <input type="submit" value="Siguiente" name="validar"> </form> </body> </html>