Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 2 of 2
  1. #1
    Junior Member
    Join Date
    Nov 2009
    Posts
    2
    Member #
    20452
    So I am still kinda new with javascript. I have written out a page with a username and password stored cookies and it still is not perfect. I need the password to be displayed on the confirmation page as well as the username. I know I have the username being displayed right now in the code, but I still am unsure if I need to write another function and I can't seem to implement it in the page right for some reason. I need it to have both username and password fields in the alert box, or atleast the username first than the password after the username is entered and then have it write the cookie and display it on the next page. Only the username works


    Hello, "username" welcom back
    Your password is "password"

    Any help would be appriciated. Here is what I have written:


    Code:
    <html>
    <head>
    <script language="JavaScript">
    
    <!--
    
    function set_cookie ( name, value, expires_year, expires_month, expires_day, path, domain, secure )
    {
      var sugarCookie = name + "=" + escape ( value );
    
      if ( expires_year )
      {
        var expires = new Date ( expires_year, expires_month, expires_day );
        sugarCookie += "; expires=" + expires.toGMTString();
      }
    
      if ( path )
       sugarCookie += "; path=" + escape ( path );
    
      if ( domain )
       sugarCookie += "; domain=" + escape ( domain );
    
      if ( secure )
       sugarCookie += "; secure";
    
      document.cookie = sugarCookie;
    
    }
    
    function delete_cookie (user)
    {
      var cookie_date = new Date ( );  // current date & time
      cookie_date.setTime ( cookie_date.getTime() - 1 );
      document.cookie = user += "=; expires=" + cookie_date.toGMTString();
    }
    
    function get_cookie (user)
    {
      var results = document.cookie.match ( '(^|;) ?' + user + '=([^;]*)(;|$)' );
    
      if ( results )
        return ( unescape ( results[2] ) );
      else
        return null;
    }
    
    if ( ! get_cookie ( "username" ) )
    {
      var username = prompt ( "Please enter your name", "" );
      var password = prompt ( "Please enter your password", "" );
    
      if ( username )
      {
        var current_date = new Date;
        var cookie_year = current_date.getFullYear ( ) + 1;
        var cookie_month = current_date.getMonth ( );
        var cookie_day = current_date.getDate ( );
        set_cookie ( "username", username, cookie_year, cookie_month, cookie_day );
        document.location.reload( );
      }
    }
    else
    {
      var username = get_cookie ( "username" );
      var password = get_cookie("username");
      
      document.write ( "Hello" + " " + username + " "+ "welcome Back!" );
      document.write ( "<br>" );
      document.write ( "Your password is" + " " + password + "," );
      document.write ( "<br><a href=\"javascript:delete_cookie('username'); document.location.reload( );\">Delete This Damn Cookie!</a>" );
    }
    
    </script>
    </head>
    <body >
    
    
    
    
    </body>
    </html>

  2.  

  3. #2
    Junior Member
    Join Date
    Nov 2009
    Posts
    2
    Member #
    20452
    anyone?


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 05:08 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com