views:

81

answers:

1

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="css/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>
+3  A: 

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.

Chris Thompson
no it didnt help...
TIMOTHY
Yes it does help, it however might not have solved all the problems your script has.
Matti Virkkunen
oo okay, i saw in another program that the line didnt have the quotes. i thought it was suppose to, well that didnt help either, but as long as you think its a working form then i guess i can just debugg it. but what do you mean onclick handler? isnt that what i did?
TIMOTHY
and i know it helped matt, i just mean it didnt solve the problem im having.
TIMOTHY
@TIMOTHY you're right, you were. sorry I read it quickly and when I saw javascript: My mind filled in href rather than onclick. Apologies.
Chris Thompson
alright, thank you very much for your help. hopefully i can figure this out. youve given me a good push. ive checked the thing let me know if i need to do anything else to give you a score for the answer.
TIMOTHY