Click here to Skip to main content
15,917,862 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Now i cant login at all even when typing "varastomies@gmail.com" and the correct pass

What I have tried:

//Varmistukset


var email = document.forms['form']['email'];
var password = document.forms['form']['password'];

var email_error = document.getElementById('email_error');
var pass_error = document.getElementById('pass_error');

email.addEventListener('textInput', email_Verify);
password.addEventListener('textInput', pass_Verify);

function validated(){
    if (email.value != 'Varastomies@gmail.com') {
        email.style.border = "1px solid red";
        email_error.style.display = "block";
        email.focus();
        return false;
    }
    if (password.value != 'sotilas123') {
        password.style.border = "1px solid red";
        pass_error.style.display = "block";
        password.focus();
        return false;
    }

}
function email_Verify(){
    if (email.value == 'Varastomies@gmail.com') {
        email.style.border = "1px solid silver";
        email_error.style.display = "none";
        return true;
    }
}
function pass_Verify(){
    if (password.value == 'sotilas123') {
        password.style.border = "1px solid silver";
        pass_error.style.display = "none";
        return true;
    }
}
Posted
Updated 19-Nov-22 4:40am

1 solution

Without running your code at all, I would suspect what you typed, varastomies@gmail.com is not equal to Varastomies@gmail.com. Note that string comparisons are case sensitive so those two strings are not equal.
 
Share this answer
 
Comments
Miikarl Miikel 19-Nov-22 11:22am    
I hoped for simple as that answer but yea i put Varastomies@gmail.com into login right :S so i think the problem is somewhere else
Dave Kreskowiak 19-Nov-22 18:20pm    
OK, first you would NEVER validate a username and password in client-side javascript. It's incredibly easy for a user to get the username and password your code is looking for.

Next, the textInput event fires BEFORE you get a character to show up in the textbox. This means your textbox value is empty (in the event handler) on the first keypress. On the last keypress, your email value (as seen in the event handler) is actually one character short of what you typed.

It's not clear what you're ultimately trying to do with this code, so it's difficult to tell you what to do to achieve it.
Miikarl Miikel 19-Nov-22 18:31pm    
Its just for a project like it doesn't matter that someone sees the login or like that cause its just to be "fancy" but yea just trying to make it so i can login, cause i know how to do the validate with "=< 3" numbers but then it works with every email, but when i type text like that email and pass it just breaks the whole code im really newbie in coding just been on school for month or so
Dave Kreskowiak 19-Nov-22 18:49pm    
The following will not do anything until you enter an email and password and click the Submit button:
<html>
	<head>
	</head>
<body>
	<form action="javascript:validate();">
		<label for="email">Email:</label><br>
		<input type="text" id="email" width="150" /><br>

		<label for="password">Password:</label><br>
		<input type="password" id="password" width="150" /><br>

		<input type="submit" value="Submit" />
	</form>
</body>

<script>
	function validate() {
		console.log("in validate");
		console.log(document.getElementById("email").value);
		console.log(document.getElementById("password").value);
	}
</script>
</html>
Miikarl Miikel 19-Nov-22 19:03pm    
Dude thanks for help ! i forgot i needed prob to put my html to you also :D i feel stupid but the mistake was one me i found the problem it was my stupidity :D thanks alot for help

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900