I have problem with login validation using javascript. When the user doesn't provide any username or password the pop up message is showing please enter the username and password. I want that when user doesn't provide username the pop up message will come please enter the username, then if i press OK button cursor should go in txtusername textbox. In case of password also same thing should happen, cursor should go in txtpassword textbox. But in my programming the pop up message is coming but after pressing ok button cursor is not placing in expected position, please somebody modify my code. Here is my code.
<script type="text/javascript">
//Function to check valid login
function validLogin() {
if (document.getElementById("TxtName").value == "") {
alert("Please enter your UserName");
return false;
}
if (document.getElementById("Txtpassword").value == "") {
alert("Please enter your Password");
return false;
}
return true;
}
<asp:Button ID="BtnLogin" runat="server" Text="Login" onclick="BtnLogin_Click" OnClientClick="validLogin()"/>