javascript - Check if readonly file input is empty or not -


i have form input type , file browse , need enable confirm button if both valid (not empty text , 1 file selected). html code:

  <div class="modal-body">   <!-- form start -->   <div class="box-body">     <div class="form-group">       <label>name</label>       <input id="name" type="text" class="form-control" maxlength="45" placeholder="version name">     </div>     <div class="form-group">       <label>note </label>(optional)       <textarea id="note" class="form-control" rows="4" maxlength="255"></textarea>     </div>     <div class="input-group">       <span class="input-group-btn"> <span                     class="btn btn-primary btn-file" id="browsebutton"> browse&hellip; <input                         id="versionfile" type="file" name="file" />                 </span>       </span>       <input id="versionname" type="text" class="form-control" readonly="readonly">     </div>   </div> </div> <div class="modal-footer">   <button type="button" class="btn btn-default pull-left" data-dismiss="modal">close</button>   <button id="uploadversionbutton" type="button" class="btn btn-primary">upload version</button> </div> 

as can see file input text readonly , have difficult check it. thought check if name input not empty when file selected, but

$('#versionname').bind('change',validate);  

the validate function

    function validate() {    if($('#name').val().length > 0) {      var filecontrol = document.getelementbyid('versionfile');      if(filecontrol.files.length === 0) {        $("#uploadversionbutton").prop("disabled", true);        notifymessage("your file empty!", 'error');      } else {        $("#uploadversionbutton").prop("disabled", false);      }    } else {      notifymessage("please insert name client version.", 'error');      $("#uploadversionbutton").prop("disabled", true);    }  } 

doesn't work on readonly field. have idea check 2 field?


Comments