Login 
Password
  
 


JavaScript Cert. Exam
Test your skills with our JavaScript certification exam and see how you stack up right now.

Homepage
Visit our homepage and find out more about what NCSA can do for you.

Introduction to JavaScript
Using JavaScript on your Webpage
A Simple JavaScript Application
Variables & Operators
Variables
Operators
Loops & Conditionals
Loops
Conditionals
Document Object Model
Nodes
Functions & Methods
Built-in Functions
User Defined Functions
Forms & Events
Forms
Events
Browsers
Cookies
Image Maps
Timing Events

Learn More About Us
Find out more about how our certifications can benefit you.

Course Descriptions
View a complete listing of certifications available through NCSA.

Employer Programs
Visit our employer programs page and discover the options available to connect you with our customers.

Certificate Database
Lookup a certification in our online database.

Affiliate Program
Make money by helping people get the computer training and certification they need. Sign-up Here!

Support Center
If you have questions or concerns feel free to visit our online support center.


 

Cookies


The web servers cannot store the information or the history of the user. Once the browser request has been fulfilled the information about the browser’s previous actions will be lost. For example, the information such as which page was clicked, or which image was clicked will be lost. The web server cannot maintain the state of the user session. However, the maintaining the state of the user is desirable most of the times and therefore cookies are used.

 

Cookie is a variable that stores the information about the user session. It can store the name, date, or the pages being visited by the user. The cookies are stored on the user’s computer and when the user requests the same page from the same browser, the cookie is sent to the server and help server to identify the user and displays the name or the other information of the user on the web page requested. There are different types of cookies such as name cookies - that store the name of the user and helps in displaying a welcome message for the user, password cookies - that stores the passwords of the user and saves user from typing the password every time the user visits the same website, date cookies – that stores the date and time of the visit on the web page of the user and helps in displaying the last visit date and time of the user.

 

The cookies are however, expired after certain time. After which they will no longer be stored at the user’s computer. JavaScript allows you to create and read a cookie. To create a cookie, you need to use the code:

 

Document.cookie = ”name=<cookiename>;expires=< expirydate>;path=<path>;domain=<domain>;secure”;

 

The description of each property is as follows:

 

·        Name= Name of the cookie.

 

·        Expires= Expiry date of the cookie in format weekday ddmmyy hh:mm:ss GMT. By default the expiry date is set to the end of the current session.

 

·        Path= The directory path where the cookie is active or the portion of the URL for which cookie is valid. Usually the path is set to “/”which means the cookie is valid during the entire program.

 

·        Domain name= Domain portion of the URL for which the cookie is valid.

 

·        Secure = Specifies that the cookie should be transmitted over a secure link only.

 

To set a cookie you can write the code, as shown below:

 

<HTML>

<BODY>

<SCRIPT LANGUAGE="JavaScript">

 

cookie_name = "dataCookie";

var ValueEntered;

 

function setCookie() {

//Check if cookie is already set

if(document.cookie != document.cookie)

{index = document.cookie.indexOf(cookie_name);}

else

{ index = -1;}

// if the cookie value is not equal to the data entered by the user

if (index == -1)

{

ValueEntered=document.myform.text1.value;

document.cookie=cookie_name+"="+ValueEntered+"; expires=Saturday, 04-Dec-2010 05:00:00

GMT";

}

alert("cookie is set with value:  "+ValueEntered);

}

</SCRIPT>

 

<FORM NAME="myform">

 

Enter the value for cookie: <INPUT TYPE="text" NAME="text1" size="20">

<INPUT TYPE="button" Value="Set to Cookie"

onClick="setCookie()">

 

</FORM>

<?BODY

</HTML>

 

The result of the code

 

 

To get the value of cookie, you need to write the function as:

 

 

function ReadCookie(cookieName)

{

 var myCookie=""+document.cookie;

 var ind= myCookie.indexOf(cookieName);

 if (ind==-1 || cookieName=="") return "";

 var ind1= myCookie.indexOf(';',ind);

 if (ind1==-1) ind1=theCookie.length;

 return unescape(myCookie.substring(ind+cookieName.length+1,ind1));

}

 

 

To delete the cookie, you need to write the function as:

 

function deletecookie ( cookiename )

{

  var cookiedate = new Date ( );  // current date & time

  cookiedate.setTime ( cookiedate.getTime() - 1 );

  document.cookie = cookiename += "=; expires=" + cookiedate.toGMTString();

}

 


NCSA OnDemand Training Courses



Web-based Training Courses, including 7,500+ Videos & Articles, covering:

Microsoft Office
2003 | 2007
Microsoft Windows
Vista
Visio
2003 / 2007
OneNote
2003 / 2007
Project
2003 | 2007
Sharepoint
3.0
Access
2003 | 2007
Excel
2003 | 2007
Outlook
2003 | 2007
PowerPoint
2003 | 2007
Word
2003 | 2007
Office for Mac
2008
Excel for Mac
2008
Entourage for Mac
2008
PowerPoint for Mac
2008
Word for Mac
2008

Acrobat 8 Professional ADO.NET 2.0 ASP.NET 2.0 for Visual Basic 2005
C# 2005 Crystal Reports XI Exchange Server 2003
Flash 8 ActionScripting Flash 8 for Designer FrontPage 2003
Mind Manager 7 Pro + Project 2007 Mind Manager 7 Pro Fundamentals Office 2007 - What's New
Photoshop CS2 PHP Programming QuickBooks Pro 2006
SharePoint End User: Administrator SharePoint End User: Contributor SharePoint End User: Reader
Small Business Server 2003 SQL Server 2005 Visual Basic 2005
Windows Server 2003

Order NCSA OnDemand today and get access to over 7500 quality instuctor led videos and training courses covering today's most popular software programs and programming languages.

OnDemand Monthly - $25/month
No long term commitment.
Annual Member - $159/year
Save 50%off monthly price.
Premium - $249/year
Includes NCSA certifications


    

  
HOME    PRIVACY    EMPLOYERS    CERTIFICATION LIST    AFFILIATES    CONTACT US

© 2002-2010 National Computer Science Academy, All Rights Reserved.