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

    I need help with this piece of JavaScript...

    <script type="text/javascript">
    function validate()
    {
    var entry = document.forms.f.pwd1.value.toLowerCase();
    if( entry == "mike") window.location = "contentpage.htm";
    else
    {
    alert("Password is Incorrect, you should not be here");
    document.forms.f.pwd1.value="";
    }
    }
    </script>

    What is wrong with this... I am putting it on my webpage, but it isn't working, and I have looked over it a billion times... maybe it is something to do with the validate function, and the browser not understanding it? Hmm...Help plz!

  • #2
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    Can you post your form? Is your form name 'forms' if not im assuming you wanted to put forms[0]?

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,048
    Thanks
    0
    Thanked 251 Times in 247 Posts

  • #4
    New to the CF scene
    Join Date
    Dec 2004
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    No... I don't have any form syntax...(except for in the var and if statements.)
    I am trying to get a password validation field.
    P.S. Thanks Glenn for your script, although I plan to use it for reference, since I am trying to learn on my own.
    Last edited by atrsite; 12-08-2004 at 04:44 AM.

  • #5
    New to the CF scene
    Join Date
    Dec 2004
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Now that I think of it, I should have a form to apply the validation to, but how would I implement that? All I want is a username and password box to show up, then when they enter the right combo it should go to the page.

  • #6
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,048
    Thanks
    0
    Thanked 251 Times in 247 Posts
    Code:
    <script type="text/javascript">
    function validate(oForm)
    {
      var pwd = oForm.pwd1.value.toLowerCase();
      if (oForm.username.value.toLowerCase() == "atrsite" && oForm.pwd1.value.toLowerCase() == "mike"){
        window.location = "contentpage.htm";
      }
      else
      {
        alert("Username or Password is incorrect, you should not be here.");
        oForm.username.focus();
      }
    }
    </script>
    ...
    <form name="f">
    <input type="text" name="username" />
    <input type="password" name="pwd1" />
    <input type="button" value="Login" onclick="validate(this.form)" />
    </form>

  • #7
    New to the CF scene
    Join Date
    Dec 2004
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Ok, here it is...

    <table>
    <tr>
    <td>Username: </td><td><input type="text" name="user" /></td>
    </tr>
    <tr>
    <td>Password: </td><td><input type="text" name="pass" /></td>
    </tr>
    <tr>
    <td colspan="2" align="center"><input type="submit" value="Login" /></td>
    </tr>
    </table>
    </form>

    Form action:
    <script type="text/javascript">
    function validate()
    {
    var entry = document.forms[1].form1.pwd1.value.toLowerCase();
    if( entry == "mike") window.location = "contentpage.htm";
    else
    {
    alert("Password is Incorrect, you should not be here");
    document.forms[1].form1.pwd1.value="Try Again";
    }
    }
    </script>

  • #8
    New to the CF scene
    Join Date
    Dec 2004
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks...!


  •  

    Posting Permissions

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