Reputation: 335
In my form i have two text boxes txtName & txtAge . I use jquery.validate.js to make it as required field validator and it is working fine. Now my requirement is sometimes based on some business logic i need to make these 2 fields non-mandatory programatically. But if user fills txtName he needs to fill txtAge too or Vice Versa.
If either one of the field is filled other should be filled, Or both can be left empty
I'm using asp.net in server side.
Upvotes: 0
Views: 596
Reputation: 4024
if you are using the css class based validation, then you should be able to do this by simply removing/adding the "required" class in the inputs as needed.
$('#txtName, #txtAge').blur(function(){
nameElem = $('#txtName);
ageElem = $('#txtAge');
if(nameElem.val() != "" || ageElem.val() != "")
{
$('#txtAge,#txtName').addClass('required');
}else{
$('#txtAge, #txtName').removeClass('required');
}
});
Upvotes: 1