Ver Mensaje Individual
  #1 (permalink)  
Antiguo 03/10/2007, 16:41
Avatar de Masterkhan
Masterkhan
 
Fecha de Ingreso: septiembre-2006
Ubicación: En mi casa
Mensajes: 64
Antigüedad: 17 años, 7 meses
Puntos: 0
Exclamación Fallo en código de validación de formulario

Hola he hecho este script para el siguiente formulario

Código HTML:
<form name="prueba" action="hola.php" method="post" >
Nombre <input type="text" name="Nombre">
Apellidos <input type="text" name="Apellidos">
Edad <input type="text" name="Edad"> 
<input type="button" onclick="validar();" value="Consulta">
</form> 
El script

Código:
<script language="javascript">
function validar()
{
var d= document.prueba;

for(i=0;i<d.elements.lenght;i++);
{
	if(d.elements[i].value=="")
{
				alert("Debes rellenar un campo al menos");
				d.Nombre.focus();
				/*AQUÍ ME GUSTARÍA QUE EL INPUT SE PUSIERA ROJO*/
				}
			else
				{
				d.submit();
				}
		}
}
</script>
Creo que está correcto pero soy novato en Javascript y por supuesto no me va