Verifying if the password field is empty
<p>I have a login form in which the user enters the username and the password in an attempt to login to his profile. I want to dynamically verify that both the fields are filled before i start doing the server side processing. </p>

<hr>

<pre><code>&lt;form id="form" method="post" action="student.jsp"&gt;

          &lt;label&gt;&lt;strong&gt;Username :&lt;/strong&gt;&lt;br/&gt;&lt;br/&gt;
          &lt;input type="text" value="" name="username" id="idusername"&gt;
        &lt;/label&gt;&lt;br/&gt;&lt;br/&gt;

          &lt;label&gt;&lt;strong&gt;Password :&lt;/strong&gt;&lt;br/&gt;&lt;br/&gt;
          &lt;input type="text" value="" name="password" id="idpassword"&gt;
            &lt;/label&gt;&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;

          &lt;input id="minibutton" name="send" type="submit" value="Login" /&gt;
        &lt;/form&gt;
</code></pre>

<hr>

<p>I am using javascript which correctly verifies and alerts whenever the username is left blank and we attempt to login. However, it does not do so with the password field and we can get away with it being left blank.</p>

<hr>

<pre><code>$(document).ready(function(){
//global vars
var form = $("#form");
var username= $("#idusername");
var password = $("idpassword");

//On Submitting
form.submit(function(){
    if(username.val().length==0 || password.val().length==0){
                    alert('Please enter the username');
        return false;
                    }
    else
    {
                if(password.val().length==0)
                    {
                        alert('Please enter the password');
                        return false;
                    }

                 else   
                    return true;
    }
});
});
</code></pre>

<hr>

<p>I am not good at javascript but i need to use it for dynamic validation. Plaese pointy out the error in verifying the password field.</p>
