Click here to Skip to main content
15,887,347 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
JavaScript
if (document.getElementById('<%=txtName.ClientID %>').values == "" && document.getElementById('<%=txtPassword.ClientID %>').values == "")

                return false; alert("Enter Username & Password");




I am putting this code put repeatly ask alert message what can i do plz help me!!!!!
Posted
Updated 28-Aug-12 23:24pm
v2

You should move the alert statement before the return one.
 
Share this answer
 
Comments
satheeshkumar chinnadurai 29-Aug-12 5:25am    
alert not working sir
hi,

Your alert should be first.
if you first return false then remaining code will be not execute. Because its terminate the execution after return false.
Put Alert message first and then keep return statement. it should work.

JavaScript
if (document.getElementById('<%=txtName.ClientID %>').values == "" && document.getElementById('<%=txtPassword.ClientID %>').values == "")
alert("Enter Username &amp; Password");
return false; 


Thanks,
Viprat
 
Share this answer
 
v2
JavaScript
if (document.getElementById('<%=txtName.ClientID %>').value == "" && document.getElementById('<%=txtPassword.ClientID %>').value == "")
{
  alert("Enter Username & Password");
  return false; 
}

In most languages if you don't put braces to open and close the scope of the condition to be checked it only affects the first line after the condition.

As CPallini said, put the alert before the return.
And put the {} in the condition.

Hope this helps.
 
Share this answer
 
v2
Try this
HTML
if (document.getElementById('<%=txtName.ClientID %>').values == "" && document.getElementById('<%=txtPassword.ClientID %>').values == "")
{
       alert("Enter Username & Password");
       return false; 
}


Faults done by you.
1.alert is written after return.(you should write alert before return).
2.If you are writing more than one line inside if clause than use curly brackets('{' '}')..(that you have not done.
 
Share this answer
 
Comments
Member 13886236 4-Jul-18 6:19am    
when you leave text box or combo box and be empty show your a message ask you to filled

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900