Results 1 to 7 of 7

Thread: Making simple Password Form work with button AND when clicking enter

  1. #1
    Join Date
    Sep 2004
    Location
    Tallahassee, FL USA
    Posts
    264
    Thanks
    71
    Thanked 2 Times in 2 Posts

    Default Making simple Password Form work with button AND when clicking enter

    Hi,
    My client has a staff page which they wish to offer very simple password protection on. I'm using a simple javascript with a hex encoded password and have the set the page up to their specs. They are fully aware that this is NOT secure. Their goal is to have staff pages with items that may not be ready for the general public or to present to their board members and this should suffice.

    This is the sample page they gave me as a basic template: http://floridaimpactstaff.tumblr.com/

    Here is the page I created for them: http://www.flimpact.org/testlogin.html. The script works perfectly if you enter the password and then click the Login button - a popup alert informs you the password is correct and you move on to the next page. However, if you type the correct password and click Enter instead of clicking the Login in button, you get the alert, but it does NOT forward you to the page.

    You can test it yourself - the password is: easy

    I've added this script to the head, but still no luck:
    Code:
    <script type="text/javascript">
    $("input").keypress(function(event) {
        if (event.which == 13) {
            event.preventDefault();
            $("form") logIn();
        }
    });
    </script>
    Any help would be appreciated.
    Thanks,
    Deborah
    Deborah Whipp
    Web Designer
    Tallahassee, FL
    www.DWWebDesigns.com

  2. #2
    Join Date
    Mar 2010
    Location
    Florida
    Posts
    512
    Thanks
    9
    Thanked 61 Times in 59 Posts

    Default

    Try -

    replace:
    Code:
    parent.location="http://www.flimpact.org/1staff.html";
    with
    Code:
    window.location.assign("http://www.flimpact.org/1staff.html");
    -DW [Deadweight]
    Resolving your thread: First Post: => EDIT => Lower right: => GO ADVANCED => Top Advance Editor drop down: => PREFIX:Resolved

  3. #3
    Join Date
    Sep 2004
    Location
    Tallahassee, FL USA
    Posts
    264
    Thanks
    71
    Thanked 2 Times in 2 Posts

    Default

    I've changed the coding to your suggestion, but still the same issue.
    Deborah Whipp
    Web Designer
    Tallahassee, FL
    www.DWWebDesigns.com

  4. #4
    Join Date
    Mar 2010
    Location
    Florida
    Posts
    512
    Thanks
    9
    Thanked 61 Times in 59 Posts

    Default

    Ok give me a moment. Ill remake it from the beginning.
    -DW [Deadweight]
    Resolving your thread: First Post: => EDIT => Lower right: => GO ADVANCED => Top Advance Editor drop down: => PREFIX:Resolved

  5. #5
    Join Date
    Sep 2004
    Location
    Tallahassee, FL USA
    Posts
    264
    Thanks
    71
    Thanked 2 Times in 2 Posts

    Default Password Protected Page

    Thanks... I finally got it working with help from users at stackoverflow: http://www.flimpact.org/testlogin4.html, but I'll be deleting the test page soon.

    In case anyone else ever needs a very low-security password protected page, below is the coding that worked. Just remember to change YOUR_PAGE_HERE with the url of the page you want to password protect.

    Code:
        <!DOCTYPE html>
        <html>
        <head>
        <title>Login</title>
        <meta name="description" content="Staff Login.">
        <meta name="keywords" content="login page">
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
        <link rel="stylesheet" type="text/css" href="/stylesheet.css">
        
        <script type="text/javascript">
        //Powered by DCScript
        function logIn() {
        var pass=unescape("%65%61%73%79");
        switch (document.lform.login.value)
        {
        case pass:
        alert("Valid password. Access granted");
        parent.location="YOUR_PAGE_HERE";
        return false; 
        break;
        default : alert("Invalid password. Please try again.");
           }
        }
        //Encoding/Decoding hex can be done at http://nickciske.com/tools/hex.php
        </script>
        
        <script type="text/javascript">
        $('.input').keypress(function (e) {
          if (e.which == 13) {
            $('form#lform').submit();
            return false;    //<---- Add this line
          }
        });
        </script>
        
        </head>
        
        
        <body>
        
        
        <center>
        <form name="lform" id="lform" onsubmit="return logIn()">
        <input type="password" class="passwordinput" size="40" name="login" id="login"><br>
        <input type="button" class="loginbutton" value="Login" onClick="logIn()">
        </form>
        </center>
        
        </body>
        </html>
    Deborah Whipp
    Web Designer
    Tallahassee, FL
    www.DWWebDesigns.com

  6. #6
    Join Date
    Mar 2010
    Location
    Florida
    Posts
    512
    Thanks
    9
    Thanked 61 Times in 59 Posts

    Default

    No problem but before you go may i show you something? Ill send it to you as a pm. Its code.
    -DW [Deadweight]
    Resolving your thread: First Post: => EDIT => Lower right: => GO ADVANCED => Top Advance Editor drop down: => PREFIX:Resolved

  7. #7
    Join Date
    Sep 2004
    Location
    Tallahassee, FL USA
    Posts
    264
    Thanks
    71
    Thanked 2 Times in 2 Posts

    Default

    Absolutely - will check my messages
    Deborah Whipp
    Web Designer
    Tallahassee, FL
    www.DWWebDesigns.com

Similar Threads

  1. Making Div Button work like submit button
    By balushahi in forum JavaScript
    Replies: 1
    Last Post: 03-21-2008, 03:42 PM
  2. Replies: 2
    Last Post: 01-23-2007, 11:27 AM
  3. How to open a new window upon clicking the submission button of password...
    By bajiggity08 in forum Dynamic Drive scripts help
    Replies: 1
    Last Post: 09-18-2005, 09:37 AM
  4. Replies: 6
    Last Post: 07-08-2005, 03:25 PM
  5. Using "Enter" on Simple Password Script
    By fartie in forum JavaScript
    Replies: 0
    Last Post: 04-25-2005, 06:37 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •