JavaScript Program to Save the Selected Color Value in Cookie and Retrive the value of it

Write a JavaScript program to save the selected color value in cookie and retrive the value of it.



Source Code
<html>
    <head>
        <title>Sample Cookie</title>
    </head>
    <script>
        function saveCookie() {
            var c = document.forms.myform.color.value;
            document.cookie = "color=" + c + ";";
            alert("Cookie saved successfully !!!");
        }

        function getCookie() {
            alert(document.cookie);
        }
    </script> 
    <body>
       
    <p>Select the color</p>
    <form name="myform">
        <input type="radio" name="color" value="red">Red<br>
        <input type="radio" name="color" value="green">Green<br>
        <input type="radio" name="color" value="blue">Blue<br>
        <input type="button" value="Save Cookie" onclick="saveCookie()"> 
        <input type="button" value="Get Cookie" onclick="getCookie()"><br>
    </form>
    </body>
</html>
Output