Advertisement
afsarwebdev

Editable text field save button

Jan 16th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.94 KB | None | 0 0
  1. //HTML(index.html)
  2.  
  3. <!doctype html>
  4. <html lang="en">
  5. <head>
  6. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  7. <title>FB-Style Inline Edit Fields</title>
  8. <meta name="author" content="Jake Rocheleau">
  9. <link rel="stylesheet" type="text/css" href="style.css">
  10.  
  11. </head>
  12.  
  13. <body>
  14. <div id="wrapper">
  15. <header>
  16. <h1>demobook</h1>
  17. </header>
  18.  
  19. <section id="core">
  20. <div class="profileinfo">
  21. <h2>Update your Profile Info &rarr;</h2>
  22.  
  23. <div class="gear">
  24. <label>Primary E-Mail:</label>
  25. <span id="pemail" class="datainfo">myaddress@googlemail.com</span>
  26. <a href="#" class="editlink">Edit Info</a>
  27. <a class="savebtn">Save</a>
  28. </div>
  29.  
  30. <div class="gear">
  31. <label>Full Name:</label>
  32. <span id="fullname" class="datainfo">Johnny Appleseed</span>
  33. <a href="#" class="editlink">Edit Info</a>
  34. <a class="savebtn">Save</a>
  35. </div>
  36.  
  37. <div class="gear">
  38. <label>Birthday:</label>
  39. <span id="birthday" class="datainfo">August 21, 1989</span>
  40. <a href="#" class="editlink">Edit Info</a>
  41. <a class="savebtn">Save</a>
  42. </div>
  43.  
  44. <div class="gear">
  45. <label>City/Town:</label>
  46. <span id="citytown" class="datainfo">Los Angeles, CA</span>
  47. <a href="#" class="editlink">Edit Info</a>
  48. <a class="savebtn">Save</a>
  49. </div>
  50.  
  51. <div class="gear">
  52. <label>Occupation:</label>
  53. <span id="occupation" class="datainfo">Freelance Web Developer</span>
  54. <a href="#" class="editlink">Edit Info</a>
  55. <a class="savebtn">Save</a>
  56. </div>
  57. </div>
  58. </section>
  59. </div>
  60. <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
  61. <script type="text/javascript" src="scripts.js"></script>
  62. </body>
  63. </html>
  64. //Scripts(scripts.js)
  65. $(document).ready(function(){
  66. $(".editlink").on("click", function(e){
  67. e.preventDefault();
  68. var dataset = $(this).prev(".datainfo");
  69. var savebtn = $(this).next(".savebtn");
  70. var theid = dataset.attr("id");
  71. var newid = theid+"-form";
  72. var currval = dataset.text();
  73.  
  74. dataset.empty();
  75.  
  76. $('<input type="text" name="'+newid+'" id="'+newid+'" value="'+currval+'" class="hlite">').appendTo(dataset);
  77.  
  78. $(this).css("display", "none");
  79. savebtn.css("display", "block");
  80. });
  81. $(".savebtn").on("click", function(e){
  82. e.preventDefault();
  83. var elink = $(this).prev(".editlink");
  84. var dataset = elink.prev(".datainfo");
  85. var newid = dataset.attr("id");
  86.  
  87. var cinput = "#"+newid+"-form";
  88. var einput = $(cinput);
  89. var newval = einput.attr("value");
  90.  
  91. $(this).css("display", "none");
  92. einput.remove();
  93. dataset.html(newval);
  94.  
  95. elink.css("display", "block");
  96. });
  97. });
  98. //Style(style.css)
  99. * { margin: 0; padding: 0; outline: none; }
  100. html { height: 101%; }
  101. body { font-size: 62.5%; background: #fff; font-family: "Calibri", Tahoma, Arial, sans-serif; color: #444; }
  102.  
  103. img { max-width: 100%; }
  104.  
  105. a { text-decoration: none; color: #39569d; }
  106. a:hover { text-decoration: underline; }
  107.  
  108. h1 { font-weight: bold; font-size: 2.15em; line-height: 1.6em; margin-bottom: 10px; color: #676767; }
  109.  
  110. h2 { display: block; font-weight: bold; line-height: 1.85em; margin-bottom: 5px; }
  111.  
  112. h3 { font-weight: bold; font-size: 1.5em; line-height: 1.35em; margin-bottom: 2px; color: #777; padding-top: 6px; }
  113.  
  114. header h1 { font-weight: bold; font-size: 1.7em; line-height: 55px; color: #fff; }
  115. header { display: block; background: #34519b; height: 45px; padding: 0px 15px; }
  116.  
  117. #wrapper { display: block; padding: 0; max-width: 960px; margin-top: 0px; }
  118.  
  119. #core { display: block; max-width: 460px; font-family: 'lucida grande', tahoma, verdana, arial, sans-serif; margin-left: 30%; }
  120.  
  121. .profileinfo { background: #f2f2f2; width: 100%; padding: 4px 10px; border-left: 1px solid #b3b3b3; border-right: 1px solid #b3b3b3; border-bottom: 1px solid #b3b3b3; }
  122. .profileinfo h2 { position: relative; left: -250px; }
  123.  
  124. .gear { position: relative; display: block; margin-bottom: 25px; padding-bottom: 15px; border-bottom: 1px solid #d9d9d9; }
  125.  
  126. .gear a.editlink { position: absolute; right: 0; top: 13px; }
  127.  
  128. .datainfo { margin-left: 10px; font-size: 11px; color: #333; }
  129.  
  130. label { display: inline-block; font-weight: bold; color: #696969; font-size: 12px; width: 100px; }
  131.  
  132. /** @group form inputs **/
  133. .hlite { background: #e2e8f6; border: 1px solid #bdc7d8; width: 250px; margin-left: -7px; padding: 4px 7px; color: #565656; font-size: 12px; }
  134.  
  135. /** @group buttons **/
  136. .savebtn { position: absolute; right: 0; top: 13px; padding: 4px 9px; background: #5972a8; font-size: 1.2em; cursor: pointer; border: 1px solid #1a356e; color: #fff; -webkit-box-shadow: inset 0 1px 0 #8a9cc2; -moz-box-shadow: inset 0 1px 0 #8a9cc2; box-shadow: inset 0 1px 0 #8a9cc2; margin-bottom: 5px; margin-top: -5px; display: none;
  137. }
  138. .savebtn:hover { color: #fff; background: #607db7; text-decoration: none; }
  139. .savebtn:active { background: #556790; }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement