Advertisement
Guest User

FCM#70 - CRUD 5

a guest
Feb 10th, 2013
334
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. // store information in local storage
  2. function storeData() {
  3. // This is a little bit of future proofing
  4. if (!submit.key) {
  5. // if there is no key, this is a new item and needs a new key
  6. var id = "ubuVers" + Math.floor(Math.random()*10000001);
  7. } else {
  8. // set the id to the existing key we are editing
  9. id = submit.key;
  10. };
  11.  
  12. // I like to give all my form elements their own ids to give myself access
  13. // outside of the form as well as simple access inside of it
  14. var ubuVersNumValue = ge('ubuVersNum').value,
  15. ubuVersNameValue = ge('ubuVersName').value,
  16. ubuVersDict = {version: ubuVersNumValue, release: ubuVersNameValue};
  17.  
  18. // log out those values as a double check
  19. console.log(ubuVersNumValue);
  20. console.log(ubuVersNameValue);
  21.  
  22. // set the item in localstorage
  23. // note the stringify function
  24. localStorage.setItem(id, JSON.stringify(ubuVersDict));
  25.  
  26. // log out the whole local storage
  27. console.log(localStorage);
  28. ge('submit').value = 'Add';
  29.  
  30. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement