ahmed salah

ahmed salah

  • NA
  • 530
  • 149.9k

If username stored in local storage open new web page

Aug 4 2016 7:11 AM
I have web page index have two input type text username and username2
and checkbox save and button save when client write username and username2 and checkbox save checked then click save button
it will store in local storage i dont have any problem in that
I need actually if username and username2 exist or stored in local storage go to web page index2
my code as bellow working but only i need to modify it if exist local storage go to web page index2
  1. @{  
  2.     Layout = null;  
  3. }  
  4.   
  5. <!DOCTYPE html>  
  6.   
  7. <html>  
  8. <head>  
  9.     <meta name="viewport" content="width=device-width" />  
  10.     <title>Index</title>  
  11.     <script src="~/Scripts/jquery-1.10.2.js"></script>  
  12.     <script>  
  13.         $(function () {  
  14.   
  15.             if (localStorage.chkbx && localStorage.chkbx != '') {  
  16.                 $('#save').attr('checked''checked');  
  17.                 $('#username').val(localStorage.username);  
  18.                 $('#username2').val(localStorage.username2);  
  19.             } else {  
  20.                 $('#remember_me').removeAttr('checked');  
  21.                 $('#username').val('');  
  22.                 $('#username2').val('');  
  23.             }  
  24.   
  25.             $('#btn').click(function () {  
  26.   
  27.                 if ($('#save').is(':checked')) {  
  28.                     // save username and password  
  29.                     localStorage.username = $('#username').val();  
  30.                     localStorage.username2 = $('#username2').val();  
  31.                     localStorage.chkbx = $('#save').val();  
  32.                 } else {  
  33.                     localStorage.username = '';  
  34.                     localStorage.username2 = '';  
  35.                     localStorage.chkbx = '';  
  36.                 }  
  37.             });  
  38.         });  
  39.     </script>  
  40.   
  41. </head>  
  42. <body>  
  43.     <div class="container">  
  44.         <form class="form-signin">  
  45.             <h2 class="form-signin-heading">Please sign in</h2>  
  46.             <input type="text" class="input-block-level" placeholder="username" id='username'>  
  47.             <input type="text" class="input-block-level" placeholder="username2" id="username2">  
  48.             <label class="checkbox">  
  49.                 <input type="checkbox" value="save" id="save"> save  
  50.             </label>  
  51.             <button class="btn btn-large btn-primary" id="btn" type="submit">save</button>  
  52.         </form>  
  53.     </div>   
  54. </body>  
  55. </html>  
 

Answers (3)