Click here to Skip to main content
15,896,207 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hey guys,

I am 6 textboxes-> 3 for phone and 3 for cell.

i using clientside validation like

if(phone1=="")
{
show error message..
}

now problem is what

there should work validation for one thing at a time
for example--phone is required if cell textboxes are empty

and cell no. is required if phone texboxes are blank..


i am using following approach to do so...



C#
else if (EmergencyPhone1 == "") {

                           document.getElementById('ContentPlaceHolder2_lblShowError').style.display = 'inline';
                           document.getElementById('ctl00_ContentPlaceHolder2_txtEmergencyPhone1').focus();
                           //  document.getElementById('ctl00_ContentPlaceHolder2_txtEmergencyPhone1').style.borderColor = "Red";
                           flag = false;
                       }

                       else if (EmergencyPhone2 == "") {

                           document.getElementById('ContentPlaceHolder2_lblShowError').style.display = 'inline';
                           document.getElementById('ctl00_ContentPlaceHolder2_txtEmergencyPhone2').focus();
                           //  document.getElementById('ctl00_ContentPlaceHolder2_txtEmergencyPhone2').style.borderColor = "Red";
                           flag = false;
                       }

                       else if (EmergencyPhone3 == "") {

                           document.getElementById('ContentPlaceHolder2_lblShowError').style.display = 'inline';
                           document.getElementById('ctl00_ContentPlaceHolder2_txtEmergencyPhone3').focus();
                           //  document.getElementById('ctl00_ContentPlaceHolder2_txtEmergencyPhone3').style.borderColor = "Red";
                           flag = false;
                       }

                       else if (EmergencyCell1 == "") {

                           document.getElementById('ContentPlaceHolder2_lblShowError').style.display = 'inline';
                           document.getElementById('ctl00_ContentPlaceHolder2_txtEmergencyCell1').focus();
                           flag = false;
                       }

                       else if (EmergencyCell2 == "") {

                           document.getElementById('ContentPlaceHolder2_lblShowError').style.display = 'inline';
                           document.getElementById('ctl00_ContentPlaceHolder2_txtEmergencyCell2').focus();
                           flag = false;
                       }

                       else if (EmergencyCell3 == "") {

                           document.getElementById('ContentPlaceHolder2_lblShowError').style.display = 'inline';
                           document.getElementById('ctl00_ContentPlaceHolder2_txtEmergencyCell3').focus();
                           flag = false;
                       }




please help me ..it's urgent.
Posted
Updated 17-Jan-14 0:05am
v2
Comments
Rahul_Pandit 17-Jan-14 6:06am    
i am facing problem in conditioning
Karthik_Mahalingam 17-Jan-14 7:03am    
what if both are empty ??

Please explain your test cases
Rahul_Pandit 17-Jan-14 7:20am    
hey my test cases are

1. if phone is filled then no need to validate cell.
2.if cell is filled then no need to validate phone.
3.if both are empty user need to fill atleast one.

Hello,
You should use the javascript ValidatorEnable() method.
Example :
ValidatorEnable($("#your_validator_id"), false)
 
Share this answer
 
Comments
Rahul_Pandit 17-Jan-14 6:29am    
thank for reply but I am not using specific client validation.i am checking value and displaying error message and return false.so no validationEnable.Can you provide some javascript conditioning to do so.
Ahmed Bensaid 17-Jan-14 11:32am    
if (EmergencyPhone1 = "" && EmergencyPhone2 = "" && EmergencyPhone3 = "") {

if (EmergencyCell1 = "" && EmergencyCell2 = "" && EmergencyCell3 = "") {

#ErrorMessage

}
else {

#OK (One EmergencyCell at least is filled)

}


}
else {

#OK (One EmergencyPhone at least is filled)

}
Rahul_Pandit 21-Jan-14 3:28am    
I have solved it myself but your solution is very close to solve my problem.so i accept it.thanks for ur help dude.
Ahmed Bensaid 21-Jan-14 4:32am    
You are welcome ;)
if ((EmergencyPhone1 != "" && EmergencyPhone2 != "" && EmergencyPhone3 != "" || (EmergencyCell1 != "" && EmergencyCell2 != "" && EmergencyCell3 != "")){return true;}

else
{return false and set focus on the basis of condioning.}
 
Share this answer
 

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