JavaScript Program to Save Password in Cookie

Write a JavaScript program to create a form having username and password and save the password in cookie.

Write a webpage that displays a form that contains an input for username and password. user is prompted to enter the input and password and password becomes value of the cookie. Write the JavaScript function for storing the cookie . it gets executed when the password changes.



Source Code
<html>
<head>
    <title>HTML Form and Cookie</title>
    <script>
        function storeCookie()
        {
            var un = document.getElementById('uname').value;
            var pd = document.getElementById('pwd').value;

            document.cookie = "Password=" + pd;
            alert("Cookie Updated!\n" + document.cookie);
        }
    </script>
</head>
<body>
<form name="myform" action="#">
    Enter the Username <input type="text" id="uname"/><br><br>
    Enter the Password <input type="password" id="pwd"/><br><br>
    <input type="button" value="Submit" onclick="storeCookie()">
</form>
</body>
</html>
Output