Ver Mensaje Individual
  #14 (permalink)  
Antiguo 30/01/2010, 05:51
Avatar de Alun
Alun
 
Fecha de Ingreso: diciembre-2009
Ubicación: Liverpool
Mensajes: 140
Antigüedad: 14 años, 5 meses
Puntos: 4
Respuesta: cofirmar si eres "humano"

Bueno, ayer terminamos de ver en clase este ejercicio. Dejo aquí el código por si alguien necesita uno.

Código HTML:
<html>
	<head>
		<title>Captcha</title>
		<script language="JavaScript" type="text/javascript">
			<!--
			var imagenes = new Array('1.jpg','2.jpg');
			var valor = new Array('1','2');
			var aleatorio = Math.random();
			
			if (aleatorio<.5)
			{
				aleatorio=0;
			}
			else
				{
					aleatorio = 1;
				}
			
			function mostrarCaptcha()
			{
			var imagen = document.getElementById('captcha').src = imagenes[aleatorio];
			}
			function validarCaptcha()
			{
			var solucion = valor[aleatorio];
			var tx_respuesta = document.getElementById('tx_captcha').value;
			if(solucion == tx_respuesta)
			{
				alert('correcto');
			}
			else
				{
					alert('incorrecto');
				}
			}
			
				//-->
		</script>
	</head>
	<body onLoad="mostrarCaptcha();">
		<form name="formu">
			<img id="captcha">
			<input type="text" id="tx_captcha" onBlur="validarCaptcha();">Escribe los caracteres<br>
		</form>
	</body>
</html> 

Gracias a todos los que ayudasteis =)

Un saludo: Alun.