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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    HTML LOGIN HELP!!!! Urgent pls help me :)

    i am having a simple login system, but i need some help i want to assign an if else statement my code is this :
    what i need is if i login to sales if navigates to sales page,
    if other then go to other page pls help me It is very important for me
    Thanks is advance


    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>ENTER USER NAME&nbsp; ENTER PASSWORD</title>
    <style type="text/css"> 
    .style1 {
    text-align: center;
    }
    </style>
    </head>
    
    <body style="background-color: #AFC8C7">
    <script type = "text/javascript"> 
    
    // Note: Like all Javascript password scripts, this is hopelessly insecure as the user can see 
    //the valid usernames/passwords and the redirect url simply with View Source. 
    // And the user can obtain another three tries simply by refreshing the page. 
    //So do not use for anything serious!
    
    var count = 2;
    function validate() {
    var un = document.myform.username.value;
    var pw = document.myform.pword.value;
    var valid = false;
    
    var unArray = ["HR", "Admin", "IT", "Sales"]; // as many as you like - no comma after final entry
    var pwArray = ["hr123", "admin123", "it123", "sales123"]; // the corresponding passwords;
    
    for (var i=0; i <unArray.length; i++) {
    if ((un == unArray[i]) && (pw == pwArray[i])) {
    valid = true;
    break;
    }
    }
    
    if (valid) {
    alert ("Login was successful");
    window.location = "index.html";
    return false;
    }
    
    var t = " tries";
    if (count == 1) {t = " try"}
    
    if (count >= 1) {
    alert ("Invalid username and/or password. You have " + count + t + " left.");
    document.myform.username.value = "";
    document.myform.pword.value = "";
    setTimeout("document.myform.username.focus()", 25);
    setTimeout("document.myform.username.select()", 25);
    count --;
    }
    
    else {
    alert ("Still incorrect! You have no more tries left!");
    document.myform.username.value = "No more tries allowed!";
    document.myform.pword.value = "";
    document.myform.username.disabled = true;
    document.myform.pword.disabled = true;
    return false;
    }
    
    }
    
    </script>
    
    <form name = "myform">
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p class="style1">User Name:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <input type="text" name="username" style="width: 131px"> 
    </p>
    <p class="style1">&nbsp;Password:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp; 
    <input type="password" name="pword" style="width: 131px">&nbsp;
    </p>
    <p class="style1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <input type="button" value="Log In" name="Submit" onclick= "validate()" style="width: 96px">
    </p>
    
    </form>
    <div style="position: absolute; width: 100px; height: 100px; z-index: 1; left: 136px; top: 252px" id="layer1">
    </div>
    <p>&nbsp;</p>
    </body>
    
    </html>
    Last edited by VIPStephan; 01-16-2012 at 12:47 PM. Reason: wrapped code BB tags, highlighted important notice in code

  • #2
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,783
    Thanks
    6
    Thanked 1,022 Times in 995 Posts
    1. In future, please wrap any code you post in between [CODE][/CODE] tags (e. g. by using the small ‘#’ button above the reply field). That makes it much easier to read your post and much more likely for anyone to respond.
    2. Read the posting guidelines (especially point 2) regarding words like “urgent” in the thread title. As Benjamin Franklin said: “He that can have patience can have what he will.”
    3. Your problem is not an HTML problem because HTML doesn’t have if/else statements and can’t redirect based on a certain user interaction. Since I don’t see any server side code in there (altough that’s what should be used for what you want) I assume you’re actually having a JavaScript question. I’m moving your post accordingly (although I still suggest you use a server side script!).

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,147
    Thanks
    203
    Thanked 2,547 Times in 2,525 Posts
    Are you not able to make this simple alteration yourself?

    Code:
    if (valid) {
    alert ("Login was successful");
    if (un == "Sales") {
    window.location.href = "salesPage.html";
    }
    else {
    window.location.href = "otherPage.html";
    }
    return false;
    }
    The code includes a couple of typos - & nbsp instaeasd of &nbsp.

    ONCE MORE:-

    Note: Like all Javascript password scripts, this is hopelessly insecure as the user can see the valid usernames/passwords and the redirect url simply with View Source. And the user can obtain another three tries simply by refreshing the page. So do not use for anything serious!
    Last edited by Philip M; 01-16-2012 at 02:15 PM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


  •  

    Posting Permissions

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