var attempt = 3; //Variable to count number of attemptsfunction validate(){ var username = document.getElementById("username").value; var password = document.getElementById("password").value; if ( username == "MI_USUARIO" && password == "MI_CONTRASEÑA"){ alert ("Login successfully"); window.location.href = 'PAGINA WEB QUE SE REDIRECCIONA'; return false; } else{ attempt --;//Decrementing by one alert("You have left "+attempt+" attempt;"); //Disabling fields after 3 attempts if( attempt == 0){ document.getElementById("username").disabled = true; document.getElementById("password").disabled = true; document.getElementById("submit").disabled = true; return false; } }}