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.