Advertisement
Vmokuq

If, submit and click

Nov 2nd, 2018
118
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.     <script type="text/javascript">
  5.            
  6.         var setName = document.getElementById('submitname');
  7.         var reset = document.getElementById('submitreset');
  8.         var nickN = document.getElementById('nickN');
  9.  
  10.         document.addEventListener('DOMContentLoaded', () => {
  11.           if (localStorage.getItem('localN')!== null){
  12.         document.querySelector('#nickName').innerHTML = "Your nick is: <b>" + localStorage.getItem('localN') + '</b>'
  13.           }
  14.         });
  15.  
  16.         setName.addEventListener('click', function(){
  17.         var newName = document.getElementById('nickN').value;
  18.         localStorage.setItem('localN', newName);
  19.         document.querySelector('#nickName').innerHTML = "Your nick is: <b>" + localStorage.getItem('localN') + '</b>'
  20.         });
  21.  
  22.         reset.addEventListener('click', function(){
  23.         delete localStorage['localN'];
  24.         document.querySelector('#nickName').innerHTML = '<input id="nickN" autocomplete="off" autofocus placeholder="Write your nick" type="text"> <input id="submitname" type="submit" value="Set new name1">'
  25.         });
  26.     </script>
  27. </head>
  28. <body>
  29.     <div id = "nickName">
  30.       <form id="new-task">
  31.       <input id="nickN" autocomplete="off" autofocus placeholder="Write your nick" type="text">
  32.         <input id="submitname" type="submit" value="Set new name1"> </form>
  33. </div>
  34.     <div id = "newname">
  35.         <br>
  36.         <form id="setnewname">
  37.             <input id="submitreset" type="submit" value="Reset nick name">
  38.         </form>
  39.     </div>    
  40. </body>
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement