JavaScript Cookies


Link for all dot net and sql server video tutorial playlists

Link for slides, code samples and text version of the video

In this video we will discuss

1. What are cookies and why are they needed

2. How to write a cookie and read it later

Why are cookies needed

Web applications work on HTTP protocol which is a stateless protocol. This means after the web server has processed the client request for a web page, the web server will not remember anything about the client that made the request. Let us understand what this statement means with an example.

1. Design a web page with a DropDownList.

2. When the user selects a color from the DropDownList we want to change the background color of the page to the selected color.

3. We want the web application to remember the user's preferred color. On a subsequent visit to the same page it should display the page with the...

Channel:  kudvenkat
subhash ekkaluru 

Perfect 👍

Iliyas Mohammed 

clearly explained. Thankyou kudvenkat. Keep making like this

Kathleen Braden 

Great explanation! Well put together video, thank you. I have liked and subscribed.

Thanvez Ahmed 

Hi kudvenkat


is there any react with redux toutorial.

Brian Tozer 

Very clear explanation! Thanks!

Beatrix Ducz 

After added window.onload= function() the change bgColor didn't work fr me anymore, however this has nothing to do with the cookie working.

alex mcgregor 

Its not remembering the BG color for me :

<select id="ddlTheme" onchange="setColorCookie()">

<option value="Select color">Select color</option>

<option value="red">Red</option>

<option value="orange">Orange</option>

<option value="blue">Blue</option>


<script type="text/javascript">

window.onload = function() {

if(document.cookie.length != 0) {

var nameValueArray = document.cookie.split("=");

document.bgColor = nameValueArray[1];

document.getElementById("ddlTheme").value = nameValueArray[1];



function setColorCookie()


var selectedColor = document.getElementById("ddlTheme").value;

if (selectedColor != "select color")


document.bgColor = selectedColor;

document.cookie = "color=" + selectedColor + ";expires=Fri, 8 Feb 2018 01:00:00 UTC;";




Adam Klepacz 

good explanation but terrible accent bro :D Work on your accent :D

Wilfredo Mendez 

Clear, concise and to the point, excellent tut.

Rajesh Chaubey Ui-Developer 

this is working properly on internet explorer but not working in google chrome. why??

When i put my code in if condition my code like

// Window onload Function start

window.onload = function() {

// alert("Hi I am Coockie");

if (document.cookie.length !=0) {

// alert("Hello Cookie");

var nameValueArray = document.cookie.split("=");

document.bgColor = nameValueArray[1]; document.getElementById("ddlTheme").value = nameValueArray[1]; }


it is not working any browser. why can you explain

but when i put if (document.cookie.length > 0) {

then its worked.

Nikhil Jagtap 

Best possible explaination!

Ertan Kara 

Sir you're amazing :+1:

Neha Kumari 

Nice Explanation, but my question is I tried the same example but i am not able to get the output properly. Can you let me know do we need to add some additional file or folder or anything to run cookie examples. I am working in notepad++. Please help me out in this.



When we want to do multi-language we prefer this way?

Saiful Islam 

Excellent tuts

Avarus Surava 

very clear, thank you !

Cameron Bauman 

When I am closing the browser, it is not remembering the color preference. Any idea what could be causing this?


very clear. thanks!

Nathan Moore 

cookie is such a weird word

Deepthi V 

Thanks a lot for the great videos playlist......

Super Khaled 

you're so good but this way of cookie is too Complex

Amador Designs 



How did no one noticed it doesnt work in chrome? any fix for this?

shaishav garg 

Couldn't be explained better than this. Excellent Work!!!

DR Productions 

how can i access it in C#

Jack Reacher 

How do you retrieve the value stored in a _specific_ cookie?

sanjay singh Sajwan 

this is working properly on internet explorer but not working in google chrome. why??


Great, Thanks.

One thing that came up is when I ran the code in VS-IDE the cookie was placed and read,

When I copied and made another HTML document with NotePadd++ the Cookie didn't work...

jay dee 

clear, practical and Excellent tutorial !

Ігор Фед 

Дуже добий урок, як і інші уроки цього автора.

jitu jahagirdar 

wow your so genius..!

I saw your profile. I want to stand beside you as compare to knowledge..!

Damian Kuzmicki 

document.bgColor dont work for me, but = selectedColor still works

Kasra Majbouri 

Thank you very much dear Kudvenkat for your beautiful tutorials about javascript, SQL, Jquery,...I really appreciate for that. 

Best Regards


These Videos are not playing at all

JavaScript arguments object

JavaScript Cookies

JavaScript strings and regular expressions

JavaScript substring example

Set and get multiple cookies in JavaScript

Michael Buckley 

Thank you for this helpful overview.

The Real Abhinav 

color=red;expires=Fri, 5 Aug 2016 01:00:00 UTC;

when you do split('=') the array returned will have the ';' attached to the color wont it?  which can throw an error?