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>
10
  • 4
    Asking your question entirely in capital letters makes it seem like you're shouting. It's considered rude. Please don't do it. Commented Apr 14, 2010 at 18:56
  • 6
    I love this: bash.org/?835030 :) Commented Apr 14, 2010 at 18:56
  • 1
    Sorry, didn't quite catch that, could you speak up a bit? Commented Apr 14, 2010 at 18:56
  • 7
    Just an FYI, storing or passing sensitive information in JavaScript is a HUGE security flaw. Everyone can view your source and see it. Commented Apr 14, 2010 at 18:57
  • 1
    @TIMOTHY: Is it... a DMS from the 80s? Commented Apr 14, 2010 at 19:08

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

5 Comments

Yes it does help, it however might not have solved all the problems your script has.
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?
and i know it helped matt, i just mean it didnt solve the problem im having.
@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.
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.