Click here to Skip to main content
15,895,142 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
hi i want to add a validation to two text box that only one of them can be zero,both of them cannot be zero at the same time.
Posted
Comments
choudhary.sumit 12-Dec-12 2:50am    
why don't you code this? what are you searching for?
if(textBox1.Text =="" && textBox2.Text ==""){// show error}
pree_kh 13-Dec-12 1:14am    
i don want to check if both are null or nut,i wan't to check that both of them cannot have value =0.
i have two text box:
InvoiceNumber and Account payable..
so either of them can be zero,but both of them cant be zero..
i don want to do it on server side as i don't want it to postback

Hi,

Try this

function check() {
var validate_result = true;
if (document.getElementById("<%=txt1.ClientID%>").value == 0 && document.getElementById("<%=txt2.ClientID%>").value == 0) {
alert('Display message');
validate_result = false;
}

}

 
Share this answer
 
try->

if(textbox1.text=="0" OR textbox2.text=="0")
{
//This block will execute if either box contain "0"
}
else
{
//If none of box will contain "0"
//Execute what u want
}
 
Share this answer
 
v2
C#
if(textbox1.Text=="0" && textbox2.Text=="0")
{
// error
}
else
{
//write some code
}
 
Share this answer
 
Comments
StackQ 14-Dec-12 1:32am    
u used &&(And) and i used ||(Or) operation.Not bad
[no name] 14-Dec-12 1:33am    
so whats the big deal ??
StackQ 14-Dec-12 1:34am    
nothing?gr8 idea!!
[no name] 14-Dec-12 1:35am    
Thanks... :)

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