Course Hive
Search

Welcome

Sign in or create your account

Continue with Google
or
Set and get multiple cookies in JavaScript
Play lesson

JavaScript Tutorial - Set and get multiple cookies in JavaScript

4.0 (0)
13 learners

What you'll learn

This course includes

  • 12.3 hours of video
  • Certificate of completion
  • Access on mobile and TV

Summary

Keywords

Full Transcript

Link for all dot net and sql server video tutorial playlists http://www.youtube.com/user/kudvenkat/playlists Link for slides, code samples and text version of the video http://csharp-video-tutorials.blogspot.com/2015/02/set-and-get-multiple-cookies-in.html Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help. https://www.youtube.com/channel/UC7sEwIXM_YfAMyonQCrGfWA/?sub_confirmation=1 In this video, we will discuss how to set and get multiple cookies in JavaScript. This is continuation to Part 69. Please watch Part 69 before proceeding. When we click "Set Cookie" button we want to store the following 3 key-value pairs in 3 cookies. name=Venkat; [email protected]; gender=Male; When we click "Get Cookie" button we want to retrieve all the 3 key-value pairs from the 3 cookies Modify the code in setCookie() function as shown below. function setCookie() { document.cookie = "name=" + document.getElementById("txtName").value; document.cookie = "email=" + document.getElementById("txtEmail").value; document.cookie = "gender=" + document.getElementById("txtGender").value; } The above code creates 3 cookies and stores the 3 key-value pairs. At this point document.cookie property contains the following string "name=Venkat; [email protected]; gender=Male" Now, modify the code in getCookie() function as shown below. function getCookie() { if (document.cookie.length != 0) { var cookiesArray = document.cookie.split("; "); for (var i = 0; i [ cookiesArray.length; i++) { var nameValueArray = cookiesArray[i].split("="); if (nameValueArray[0] == "name") { document.getElementById("txtName").value = nameValueArray[1]; } else if (nameValueArray[0] == "email") { document.getElementById("txtEmail").value = nameValueArray[1]; } else if (nameValueArray[0] == "gender") { document.getElementById("txtGender").value = nameValueArray[1]; } } } else { alert("No cookies found"); } }

Course Hive

Continue this lesson in the app

Install CourseHive on Android or iOS to keep learning while you move.

Related Courses

FAQs

Course Hive
Download CourseHive
Keep learning anywhere