Guest User

Untitled

a guest
Dec 10th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. /**
  2. * Created with JetBrains WebStorm.
  3. * User: ynonperek
  4. * Date: 8/26/12
  5. * Time: 9:54 AM
  6. * To change this template use File | Settings | File Templates.
  7. */
  8.  
  9.  
  10. $(function() {
  11.  
  12. var contact = {};
  13.  
  14. function save() {
  15. console.log('save');
  16. contact.name = $('#name').val();
  17. contact.number = $('#number').val();
  18. contact.email = $('#email').val();
  19. contact.color = $('#color').val();
  20. contact.gender = $('#gender').val();
  21.  
  22. localStorage.setItem('data', JSON.stringify(contact));
  23. }
  24.  
  25. function restore() {
  26. var saved_value = localStorage.getItem('data');
  27.  
  28. if ( saved_value ) {
  29. contact = JSON.parse( saved_value );
  30. }
  31.  
  32. show_all();
  33. }
  34.  
  35. function show_all() {
  36. $('#name' ).val( contact.name );
  37. $('#number').val( contact.number );
  38. $('#email' ).val( contact.email );
  39. $('#color' ).val( contact.color );
  40. $('#gender').val( contact.gender );
  41. }
  42.  
  43. $('#save').click( save );
  44. $('form').on('input', save );
  45.  
  46. $('#restore').click( restore );
  47.  
  48. $('form').submit(function() {
  49. return false;
  50. });
  51.  
  52. restore();
  53. });
Add Comment
Please, Sign In to add comment