www.webdeveloper.com
Results 1 to 3 of 3

Thread: Javascript code help

Hybrid View

  1. #1
    Join Date
    Mar 2012
    Posts
    3

    Question Javascript code help

    Code below is not working...nothing happens on clicking submit...javascript is enabled in browser..help please.

    Code:
    <html>
    
    <head>
    
    <script type="text/javascript">
    
    function match()
    {
    var aa=document.getElementById("username").Value;
    
    var bb=document.getElementById("password").Value;
    
    if(aa==null || bb==null)
    {
    alert("Enter Again");
    }
    
    
    else if((aa=="admin") && (bb=="12345"))
    {
    Alert("Hello Sir");
    }
    else if((aa=="guest") && (bb=="67890"))
    {
    Alert("Hello Guest");
    }
    else
    {
    Alert("Enter Valid Info");
    }
    
    
    
    }
    </script>
    
    
    
    </head>
    
    <body>
    
    
    Username:<input type="text" id="username"/><br/>
    
    Password:<input type="text" id="password"/><br/>
    
    <input type="submit" onClick="match()"/>
    
    
    
    
    </body>
    
    
    </html>

  2. #2
    Join Date
    May 2004
    Location
    chennai, tamil nadu, India
    Posts
    448
    Alert should be alert
    Chris, Senior Developer,
    Php laravel developers,
    www.chrisranjana.com

  3. #3
    Join Date
    Mar 2012
    Posts
    14
    Also, you should avoid placing your curlybraces on the line after your parenthesis(). Some say its a matter of preference but it can matter in certain circumstances. A bad habit to start early on. Proper syntax is :
    Code:
    function myFunction() {
      var myVariable = "Welcome";
      alert(myVariable);
    }
    I would also avoid the use of non-descriptive variables such as "aa" or "bb". Use something that describes what the variable holds without being too lengthy. There is nothing wrong with username or password as variable names. Again, being picky but its a bad habit to start early on.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles