create an simple login form in javascript

<!DOCTYPE html>
<html>
<head>
    <title>Login Form</title>
</head>
<body>
    <h2>Login Form</h2>
    <form id="loginForm">
        <label for="username">Username:</label><br>
        <input type="text" id="username" name="username"><br>
        <label for="password">Password:</label><br>
        <input type="password" id="password" name="password"><br><br>
        <button type="button" onclick="login()">Login</button>
    </form>

    <script>
        function login() {
            const username = document.getElementById('username').value;
            const password = document.getElementById('password').value;

            // You can add your own authentication logic here
            if (username === 'admin' && password === 'password') {
                alert('Login successful');
            } else {
                alert('Login failed. Please try again.');
            }
        }
    </script>
</body>
</html>
927 chars
31 lines

related categories

gistlibby LogSnag