how to get cookie value in javascript

Posted by Nadh123 under JavaScript on 1/11/2013 | Points: 10 | Views : 2382 | Status : [Member] | Replies : 2
how to get cookie value in javascript

how to get cookie value in javascript

Mahendra
91-9908699686



Responses

Posted by: Sekar.C on: 1/11/2013 [Member] Starter | Points: 25

Up
0
Down
see this url
http://www.the-art-of-web.com/javascript/getcookie/

Regards
Sekar.c

Nadh123, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Shubh on: 1/11/2013 [Member] Starter | Points: 25

Up
0
Down
Hi Friend

What are Cookies ?

Web Browser and Server use HTTP protocol to communicate and HTTP is a stateless protocol. But for a commercial website it is required to maintain session information among different pages. For example one user registration ends after completing many pages. But how to maintain user's session information across all the web pages.

Storing Cookies:

The simplest way to create a cookie is to assign a string value to the document.cookie object, which looks like this:
Syntax:

document.cookie = "key1=value1;key2=value2;expires=date";

Example:

Following is the example to set a customer name in input cookie.

<html>
<head>
<script type="text/javascript">
<!--
function WriteCookie()
{
if( document.myform.customer.value == "" ){
alert("Enter some value!");
return;
}

cookievalue= escape(document.myform.customer.value) + ";";
document.cookie="name=" + cookievalue;
alert("Setting Cookies : " + "name=" + cookievalue );
}
//-->
</script>
</head>
<body>
<form name="myform" action="">
Enter name: <input type="text" name="customer"/>
<input type="button" value="Set Cookie" onclick="WriteCookie();"/>
</form>
</body>
</html>


i think it helps you
thanks in advance!!!


Shubham Agrahari

Nadh123, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response