An example to store data in local storage - HTML5

Posted by Nithadeepak under HTML 5 category on | Points: 40 | Views : 4246
The localStorage object stores the data with no time limit. It can store upto 5MB of data locally on a user device in a key-value database inside a web browser.
Below shows a simple example for storing and retrieving data in local storage.

<html xmlns="">
<head runat="server">
<script type="text/javascript">
function loc() {
var name = document.getElementById("txt1").value;
localStorage.setItem(name, "aaa");
document.getElementById("txt2").value = localStorage.getItem(name);
<form id="form1" runat="server">
<input type="text" id="txt1" />
<br />
<input type="text" id="txt2" />
<input type="button" id="btn1" value="submit" onclick="loc();" />

Comments or Responses

Posted by: CS1401 on: 8/10/2011 Level:Starter | Status: [Member] | Points: 10
hey what is the difference of normal html coding and this coding. why you specify this code belongs to html 5.can u explain?
Posted by: Nithadeepak on: 8/10/2011 Level:Bronze | Status: [Member] | Points: 10
Here I'm showing the localStorage feature of HTML5 (See how data is stored in localStorage object in the above code).
The above javascript code is worked only in those browsers which support HTML5. Using localStorage we can store upto 5MB of data locally(without cookies,session etc).
Posted by: CS1401 on: 8/11/2011 Level:Starter | Status: [Member] | Points: 10
oh thankx nitha.. its sounds good.. keep it up.

Login to post response