Is there any alternative to keyUp to check whether an input was filled?

578 views Asked by At

So I have this code:

    $(document).ready(function(){
        if($('#proofAttach-filemanager').val().length !=0){
            $('#download_now').attr('disabled', false);
        }
        else
        {
            $('#download_now').attr('disabled', true);        
        }
    });  

The field with id proofAttach-filemanager is filled up dynamically using elFinder every time I upload a file.

Since the code above is only running every time the page loads, I don't know how to update the download_now button to enable dynamically every time the field is filled (and without keyUp)

HTML Segment:

<div class="form-group col-md-12">

<label>Attachment</label>
<input type="text" id="proofAttach-filemanager" name="proofAttach" value="" class="form-control" readonly="">

<div class="btn-group" role="group" aria-label="..." style="margin-top: 3px;">
  <button type="button" data-inputid="proofAttach-filemanager" class="btn btn-default popup_selector">
    <i class="fa fa-cloud-upload"></i> Browse uploads</button>
  <button type="button" data-inputid="proofAttach-filemanager" id="download_now" class="btn btn-default download_now">
    <i class="fa fa-cloud-download"></i> Download</button>
    <button type="button" data-inputid="proofAttach-filemanager" class="btn btn-default clear_elfinder_picker">
    <i class="fa fa-eraser"></i> Clear</button>
</div>

1

There are 1 answers

7
Developer On BEST ANSWER

Writing your logic inside the change event of that text box should work.

$(document).ready(function(){
   toggleDownloadButtonAccess();

   $('#proofAttach-filemanager').change(toggleDownloadButtonAccess);

  function toggleDownloadButtonAccess(){

    var $btnDownload = $('#download_now');    
    if($('#proofAttach-filemanager').val().length !=0){
       $btnDownload.attr('disabled', false);
    }
    else
    {
       $btnDownload.attr('disabled', true);        
    }
   }


 });