Created
June 3, 2015 18:35
-
-
Save karkranikhil/8922d6d31b4924c27fdc to your computer and use it in GitHub Desktop.
file for local storage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="utf-8" /> | |
| <title>Get custom object from local storage</title> | |
| <script> | |
| var login = { | |
| username: String, | |
| password: String | |
| }; | |
| function getCustomObject() { | |
| var v = localStorage.getItem('login'); | |
| var login = JSON.parse(v); | |
| var username = login.username; | |
| var password = login.password; | |
| document.getElementById('requestedUsername').innerHTML = username; | |
| document.getElementById('requestedPassword').innerHTML = password; | |
| } | |
| </script> | |
| </head> | |
| <body> | |
| <button onclick="getCustomObject()">click me</button> | |
| <div> | |
| <label>username: </label> | |
| <span id="requestedUsername"></span> | |
| </div> | |
| <div> | |
| <label>password: </label> | |
| <span id="requestedPassword"></span> | |
| </div> | |
| </div> | |
| </body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="utf-8" /> | |
| <title></title> | |
| <script> | |
| var login = { | |
| username: String, | |
| password: String | |
| }; | |
| function saveCustomObject() { | |
| var username = document.getElementById('username').value; | |
| var password = String(document.getElementById('password').value); | |
| login.username = username; | |
| login.password = password; | |
| localStorage.setItem('login', JSON.stringify(login)); | |
| } | |
| </script> | |
| </head> | |
| <body> | |
| <form> | |
| <div> | |
| <label for="username">username: </label> | |
| <input type="text" id="username" name="username" placeholder="username" /> | |
| </div> | |
| <div> | |
| <label for="password">password: </label> | |
| <input type="text" id="password" name="password" placeholder="password" /> | |
| </div> | |
| <button type="submit" onclick="saveCustomObject()">Save Data</button> | |
| </form> | |
| </body> | |
| </html> |
Author
Author
<title>Getting Started with HTML5 local storage</title>
<script type="text/javascript" src="app.js"></script>
Simple form with name and age ...
| Name: | |
| Age: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
function save() {
}
function get() {
console.log("Getting your data from local storage.");
var myName = document.getElementById("name");
var age = document.getElementById("age");
myName.value = localStorage.getItem("name");
age.value = localStorage.getItem("age");
}
function remove() {
console.log("Removing data from local storage.");
localStorage.removeItem("name");
localStorage.removeItem("age");
}
function clearStorage() {
console.log("Clearing local storage.");
localStorage.clear();
}
function saveComplexData() {
console.log("Saving complex data to local storage.");
var myName = document.getElementById("name");
var age = document.getElementById("age");
var personObject = new Object();
personObject.name = myName.value;
personObject.age = age.value;
localStorage.setItem("person", JSON.stringify(personObject));
}
function restoreComplexData() {
console.log("Restoring complex data from local storage.");
var myName = document.getElementById("name");
var age = document.getElementById("age");
var personObject = JSON.parse(localStorage.getItem("person"));
myName.value = personObject.name;
age.value = personObject.age;
}
function saveArrayData() {
console.log("Saving array data to local storage.");
var myArrayObject = [];
}
function restoreArrayData() {
console.log("Restoring array data from local storage.");
}
function load() {
}