I'm trying to build a server control that has a radiobuttonlist with 2 items and a textbox.
THe radio buttons are YES en NO options.

When YES is selected I want the textbox to be visible and it must be required to fill in.
On NO, the textbox becomes invisible.

I manages to get the textbox to appear and disappear based on the option choice.
But how do I add validation to the textbox and remove it when not visible?

I have tried it with the ASP validators, but the jquery doesn't disable them when the textbox is not visible.

I tried something like this, but it is not working:

```
<script type="text/javascript"> 
$(function() 
{
  $('#TravelOption2_rbList').change(function() 
    { 
      var index = $('#TravelOption2_rbList input[type=radio]:checked').val(); 
      if (index != '0') 
        { 
           $('#TravelOption2_lblName2').css({'visibility':'visible'}); 
           $('#TravelOption2_txtName1').css({'visibility':'visible'}); 
           $('#TravelOption2_lblName3').css({'visibility':'visible'}); 

           // create validator (not working)
           $('#TravelOption2_txtName1').rules('add', { 
             required: true, 
             minlength: 2, 
             messages: { required: 'Required input', minlength: 'Please enter the cost.' } 
           }); 
        } else {
           $('#TravelOption2_lblName2').css({'visibility':'hidden'}); 
           $('#TravelOption2_txtName1').css({'visibility':'hidden'}); 
           $('#TravelOption2_lblName3').css({'visibility':'hidden'}); 

           // remove the validator here
        } 
    });
});
</script>

```

I have seen a lot of examples but they are not working for me.