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> |
karkranikhil
commented
Jun 3, 2015
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