Help! Need javascript for onclick

Discussion in 'JavaScript' started by scorpion896, Jan 4, 2009.

Thread Status:
Not open for further replies.
  1. #1
    Hello,
    Basically I have a page on my site where i just want it blank with a button saying enter restricted area here asking for a password (no username)... or some kind of form that asks for just a password... when the correct password is written it will take me one place when the wrong password is written it will take me to another..

    I dont think its onclick actually but whatever lol

    Can anyone help?
     
    scorpion896, Jan 4, 2009 IP
  2. astupidname

    astupidname Peon

    Messages:
    12
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    If you can use php, look in to that. Javascript is not to be used for any type of password protection as it is not secure. Any user can view the password by viewing source or looking in the .js file.
    Try googling "php password protection"
     
    astupidname, Jan 5, 2009 IP
  3. Jaguarjace

    Jaguarjace Guest

    Messages:
    52
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    here's one:
    
    <html>
    <head>
    <SCRIPT LANGUAGE="JavaScript">
    <!-- Begin
    function Continue(){
    var done=0;
    var password=document.access.password.value;
    if (password=="mypassword") { window.location="http://www.website.com/access-granted.htm"; done=1; }
    if (done==0) { window.location="http://www.website.com/access-denied.htm"; }
    }
    // End -->
    </SCRIPT>
    </head>
    <body onLoad="javascript:alert('You need to enter a password to continue!');">
    <center><br><br><br><br><br><br><br><br><br><br><br>
     <form name=access>
     <input type=password name=password size="19" onkeypress="return onEnter(event,this.form);"><br>
     <input type="button" value="Enter Restricted Area Here!" name="abutton" onclick="Continue();">
     </form>
     <script>
                  function onEnter( evt, frm ) {
     var keyCode = null;
    
     if( evt.which ) {
     keyCode = evt.which;
     } else if( evt.keyCode ) {
     keyCode = evt.keyCode;
     }
     if( 13 == keyCode ) {
    Continue();
     return false;
     }
     return true;
     }</script>
      </center>
      </body>
      </html> 
    
    Code (markup):
    *Like astupidname said, it still can be opened in view sorce :(
     
    Jaguarjace, Jan 7, 2009 IP
  4. ferdousx

    ferdousx Peon

    Messages:
    168
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    astupidname is right. If you have the password is js then its no use of usig it. But for your case, i guess you are looking for javascript 'prompt'.
     
    ferdousx, Jan 7, 2009 IP
  5. Jaguarjace

    Jaguarjace Guest

    Messages:
    52
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    here's the one for a javascript prompt:
    
    <html>
    <head>
    <SCRIPT language="JavaScript">
    var password;
    var access="mypassword";
    password=prompt('You need to enter a password to continue!',' ');
    if (password==access)
      window.location="http://www.website.com/access-granted.htm";
    else
       {
        window.location="http://www.website.com/access-denied.htm";
        }
    </SCRIPT>
    </head>
    <body>
    </body>
    </html>
    
    Code (markup):
     
    Jaguarjace, Jan 7, 2009 IP
Thread Status:
Not open for further replies.