Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jun 2004
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Username/Password validation using Select Case

    Hi!

    I am busting my head attempting to figure out this code. As you can see, if you type the username "KFoster" and the password "MST3K", you should be directed to another website. I've been through the code several times but to no avail. Here it is . . . (sorry it is heavily commented)

    -Many thanks

    <html>
    <head>
    <title>Login Form</title>
    </head>

    <!--Begin body of HTML document with formatting -->
    <body background="../bkgnd.gif">

    <H1 align="center"><font color="#000080" face="Verdana">Hidden Valley Vineyards Login Form</H1>
    <center><img src="vine.jpg"></center>

    <!--Form Name is frmLogin -->
    <form method="post" name="frmLogin" action="javascript:void(0)">

    <center><table border="0" width="300" cellspacing ="0" cellpadding="1">
    <tr>

    <!--Create 2 text boxes and assign values -->
    <td><font color="#000080" face="Verdana">User Name: </td><td><input type="text" name="txtUserName" size="22"></td><br><br>
    </tr>
    <tr>
    <td><font color="#000080" face="Verdana">Password: </td><td><input type="text" name="txtPassword" size="22"></td> <br><br>

    <!-- Create Dropdown list for all departments -->
    <tr>
    <td><font color="#000080" face="Verdana">Department: </td>
    <td><select size="1" name="1stDepartment">
    <option value="../administration">Administration</option>
    <option value="customer">Customer</option>
    <option value="employee">Employee</option>
    <option value="finance">Finance</option>
    <option value="hr">Human Resources</option>
    <option value="it">Information Technology</option>
    <option value="management">Management</option>
    <option value="manufacturing">Manufacturing</option>
    <option value="marketing">Marketing</option>
    <option value="webmaster">Webmaster</option>
    </select>
    </td>
    </tr>
    </table>

    <br><br>
    <!--Create 1 button and assign a function(login()) to the button(btnLogin) -->
    <input type="button" value="Go to the Department Website" name="btnLogin" onClick="login()">

    <!--Create 1 button to clear the screen -->
    <input type="reset" value="Clear Form" name="btnClear">
    </form>
    </center>
    </body>

    <script language="javascript">

    <!-- Create function login() -->
    function login(){

    <!-- Declare three variables -->
    var strUserName, strPassword, strDepartment;

    <!-- Assign intPrice to txtPrice textbox -->
    strUserName=document.frmLogin.txtUserName.value;

    <!-- Assign intTax to txtTax textbox -->
    strPassword=document.frmLogin.txtPassword.value;

    <!-- Assign intTax to txtTax textbox -->
    strDepartment=document.frmLogin.1stDepartment.value;

    switch (strUserName){

    case "KFoster":
    if (strPassword == "MST3K") {
    window.location.href = strDepartment + ".htm";
    }
    else{
    window.location.href = "loginFormJS.htm";
    }


    break;

    }
    }
    </script>

    </html>

  • #2
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The biggest problem is that names can not begin with a numeric.
    Rename your select option menu.

    • <select size="1" name="1stDepartment">


    A few other problems are:

    Move your script into the <head> of the document.
    Currently it appears after the closing body tag.

    Using this script/approach. Your login is not secure in that a user can simply view source and grab a username/password or the next page value.

  • #3
    New to the CF scene
    Join Date
    Jun 2004
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    It Works!

    That's it! The code now works. It's no big deal the source can be seen, it was just a test to see if I could do it. Many thanks!

    If you have Paypal, just give me your account and I'll send you five bucks for your help!

    Many thanks!

    Kevin

  • #4
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm happy to hear you were able to resolve your problem.
    But, although I appreciate your offer of remuneration there really is no need. You will find that the members of Coding Forums volunteer their time and freely assist anyone seeking a solution to any number of coding problems.

    Glad I could help.
    And welcome to Coding Forums....

    .....Willy


  •  

    Posting Permissions

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