开发者

Making a login Using JavaScript, Will Incorporate PHP Later

开发者 https://www.devze.com 2022-12-27 10:41 出处:网络
not sure why my code wont work, im teaching myself javascript i know php moderatly and i also know the intelligence of using java to hold a password and username, but at the moment i just want the scr

not sure why my code wont work, im teaching myself javascript i know php moderatly and i also know the intelligence of using java to hold a password and username, but at the moment i just want the script to work.

<html>
  <head>

    <title>34webs</title>

    <link rel="stylesheet" href="c开发者_开发百科ss/lightbox.css" type="text/css" media="screen" />

    <link rel="stylesheet" type="text/css" media="screen" href="main.css">

    <script type="text/javascript" src="js/prototype.js"></script>
    <script type="text/javascript" src="js/scriptaculous.js?load=effects,builder"></script>
    <script type="text/javascript" src="js/lightbox.js"></script>

    <script type="javascript" >

    function logintry (){

    var usern = document.logn.username.value;
    var passw = document.logn.password.value;

    if(usern == blue && passw == bluee){


    alert('password is correct!');

    }else{

    alert('password is wrong');

    }



    }


    </script>

      </head>

      <body>

    <div id="bod">

      <div id="nav">
        <p id="buttonhead">34 web</p>
        <a href="#" class="button">HOME</a>
        <a href="#" class="button">NEWS</a>     
        <a href="#" class="button">DOWNLOADS</a>
        <a href="#" class="button">ERA</a>  
        <a href="#" class="button">IE BROWSER</a>
        <a href="#" class="button">DRIVERS</a>      

        <form name="logn">
        <table style="margin:0 auto; background:#0174DF; color:white;">
        <tr>
        <td>
        Username<br>
        <input type="text"
               name="username"
               value="">
        </td>
        </tr>
        <tr>
        <td>
        Password<br>
        <input type="password"
               name="password"
               value="">        
        </td>
        </tr>
        <tr>
        <td style="text-align:center;">
        <input type="button"
               name="Submit"
               value="submit"
               onclick= javascript: logintry()>         
        </td>
        </tr>
        </table>



        </form>
      </div>


You are doing a comparison to a variable name, not a string. Change it to

if( usern == "blue" && pw =="bluee"){
  //do stuff
}

Edit After you comment, I took another look at your code, you need to surround the javascript: logintry() call with quotes. You are correct in using onclick. You need to remove the "javascript:" That is the syntax when you are using href. Onclick will automatically call the script and doesn't need the protocol prefix.

0

精彩评论

暂无评论...
验证码 换一张
取 消