简体   繁体   中英

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

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>

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);        
    }
   }


 });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM