Search code examples
javascriptjquerydisabled-control

How to enable other controls when a user is typing in a text box and disable if he deletes or text box is empty?


I'm trying to disable a group of controls based on a text box. if the user has entered a value in that text box the controls should be enabled and if the user deletes value or if it remains empty the controls should be disabled.


Solution

  • assume your text box ID is TxtBoxName and assume you put your controls inside div or any other container and its name is controls , the following is my solution

    $('#TxtBoxName').on('change',function(){
        if($(this).val().length == 0)
        {
            $('#controls').attr('disabled','disabled');
        }
        else 
        {
            $('#controls').removeAttr('disabled');
        }
    })