I need to write a function that accepts a specific username and password. if the password is wrong it displays an error box if its right then it will submit.
i know this is a pretty basic question but its one of those things thats hard to word the right way on google, any help would be greatly appreciated.
Here is my code:
function logon (userName, password)
{
userName = document.GetElementById("testusername");
password = document.GetElementById("testpassword");
if(userName == "username" && password == "password")
{
ONSUtils.LoadPage('pgMain');
}
else
{
// Show Error Message Here
}
}
The problem is that you are comparing the actual DOM to the strings “username” and “password”. You need to use the
valueproperty instead.That being said, it isn’t wise to put usernames and passwords in javascript files because they are transfered to the end-user and can be plainly read making hacking your security really easy. If you need to do security checks, it really ought to be server-side.