Estoy tratando de usar Javascript para validar la entrada del usuario antes de las redirecciones de página. Los usuarios pueden ingresar la identificación del estudiante, el nombre o el sexo y, según su entrada, serán redirigidos a una URL.
Sin embargo, parece que no obtengo las entradas múltiples correctamente en mi javascript y no sucedió nada cuando se hace clic en el botón Enviar.
He probado diferentes soluciones que encontré aquí.
vea mi código JavaScript a continuación;
var attempt = 3; // Variable to count number of attempts. // Below function Executes on click of login button. function validate(){ var username = document.getElementById("studentid").value; if ( studentid == "12345" || studentid == "Daniel" || studentid == "Boy"){ alert ("Correct Input"); window.location = "https://www.google.com"; // Redirecting to other page. return false; } else{ attempt --;// Decrementing by one. alert("ATTENTION!\nInvalid student ID!\nNot associated with any student\nYou have left "+attempt+" attempt;"); // Disabling fields after 3 attempts. if( attempt == 0){ document.getElementById("studentid").disabled = true; document.getElementById("submit").disabled = true; return false; } } }He intentado usar las soluciones a continuación;
if ( studentid == "#12345, #Daniel, #Boy"));{ alert ("correct input"); window.location = "https://www.google.com"; // Redirecting to other page. if ( studentid == '12345', 'Daniel', 'Boy'){ alert ("correct input"); window.location = "https://www.amazon.com"; // Redirecting to other page.¡Después de tantos intentos, por fin lo conseguí!
var attempt = 3; function check(form) { if(form.studentid.value == "12345" || form.studentid.value == "DANIEL" || form.studentid.value == "BOY") { window.location.replace('https://www.google.com') return false; } else { attempt --;// Decrementing by one. alert("ATTENTION!\nInvalid student ID!\nNot associated with any student!\nYou have left "+attempt+" attempt;"); // Disabling fields after 3 attempts. if( attempt == 0){ document.getElementById("studentid").disabled = true; document.getElementById("submit").disabled = true; return false; } } }