Enable next input field when not empty

Enable next input field when not empty

Hello,

I am looking for some help with the following function.

I have disabled a file input field which has a textbox above it. I am trying to make it so that when there is text in the textbox the file field is enabled and disabled when it is emtpy.

I do not want to assign id's to the file inputs so im trying to use the current jQuery selector.


  1.     $('.disable').click(function(event){
  2.             var $this = $(this);
  3.              var file = $this.closest('input[type=file]');
  4.         if($(this).val() === ""){
  5.             $($file).attr('disabled', true);
  6.         } else {
  7.             $($file).removeAttr('disabled');
  8.         }
  9.         event.stopPropagation();
  10.     });

However I am receiving a $file is undefined error?

Thanks.