JavaScript Program Validate User Login

Write a JavaScript program check for valid user login.



Source Code
<html>
<head>
    <title>Returning a value from a function</title>
<script>
function ValidateLogon(id,pwd)
{
    var ReturnValue;
    if (id == 'Admin' && pwd == '1234')
    {
        ReturnValue = true;
    }
    else
    {
        ReturnValue = false;
    }
    return ReturnValue;
}
</script>
</head>
<body>
<script language="Javascript" type="text/javascript">
    var user;
    var pwd;
    var valid;
    user = prompt('Enter user ID',' ')
    pwd = prompt('Enter password',' ')
    valid = ValidateLogon(user, pwd)
    if ( valid == true)
    {
        alert('Valid Logon')
    }
    else
    {
        alert('Invalid Logon')
    }
</script>
</body>
</html>
Output





"Coding Hub - Learn to code" app now available on Google Play Store