JavaScript – Cookie with MultipleNames


Is it possible to set multiple cookie names in javascript ?


Yes, we can set multiple names in the cookie which should be seperated by colen(:).

Why we set multiple cookie names ?

If there is a form with multiple fileds like Name,Age,PIN Number,Tax Number,SSN number,Mobile Number,Address and other personal information.

While submitting the form the fields which we required to set as cookie can be done with multiple names.

Main advantage is retriving many values from the cookie from the website.

How to set multiple cookie names in javascript ?

Suppose if i want to set the Name,SS Number,Email,Tax Number and Mobile number is document cookie,

We can easily set multiple names seperated by colen(:).

Example :

<script>
		document.cookie="Name=Abdul Kalaam;SSN=123456789;[email protected];TaxNumber=987654321;Mobile=2323232323";
		var cookieInfo = "Name=Sachin Tendulkar;SSN=123453339;[email protected];TaxNumber=122354321;Mobile=9993232423" 
		document.cookie=cookieInfo;
	</script>

Javascript interview questions basic !!!

Click to Learn More about – Javascript online learning