+ 1

My simple login validator doesnt seem to word

<!DOCTYPE html> <html> <head> <title>Log into Bus Loop App</title> <meta charset = "utf-8"/> <meta name="viewport" content="width=device-width, initial-scale=1.0"> </head> <body> <form id="loginForm"> <label for="userName">Username:</label> <input type="text" name="userName" id="userName" placeholder="Enter Username"> <br> <label for="passWord">Password:</label> <input type="text" name="passWord" id="passWord" placeholder="Enter Password"> <input type="submit" value="Login" id="submitLogin" onclick="clickSwitch()"> </form> <script> var $ = function (id) { return document.getElementById(id); } var adminUserName = "SchoolU"; var adminUserPass = "SchoolP"; function clickSwitch() { var userNameInput = $("userName").value; var passInput = $("passWord").value; if (userNameInput == adminUserName) { if (passInput == adminUserPass) { window.location.assign("https://stackoverflow.com/questions/3682805/javascript-load-a-page-on-button-click"); } else { alert ("Username and/or password is wrong"); location.reload(); } } else { alert("Username and/or password is wrong"); location.reload(); } } </script> </body> </html>

3rd Apr 2018, 5:19 AM
Tyrell Reid
Tyrell Reid - avatar
1 Resposta
+ 2
it's working
3rd Apr 2018, 6:26 AM
Sudarshan Rai
Sudarshan Rai - avatar