JavaScript Cookie with multiple Name

In order to store multiple name-value pairs of cookies in javascript, the custom object must be serialized in a JSON string which is then parsed and stored in a cookie. A separate cookie can also be used for each name-value pair. Example:

<!DOCTYPE html>
Username: <input type="text" id="name"><br>
Mail_ID: <input type="email" id="email"><br>
Id: <input type="text" id="course"><br>
<input type="button" value="Set" onclick="setCookie()">
<input type="button" value="Get" onclick="getCookie()">
function setCookie()
var cook = {}; = document.getElementById("name").value; = document.getElementById("email").value;
cook.course = document.getElementById("course").value;
var jsonString = JSON.stringify(cook);
document.cookie = jsonString;
function getCookie()
if( document.cookie.length!=0)
var cook = JSON.parse(document.cookie);
alert("Username="" "+"Mail_ID="" "+"Id="+cook.course);
alert("Cookie not available");
Please follow and like us:
Content Protection by