javascript - JS file upload validation, but instant in windows window -


i have form , did validation in js, form not send when user sends sth different .doc/.docx. (cv uploading). want faster. error instantly when file selected, not when button submitted. (in windows window).

how it? it's standard form:

<div class="form-group">                                         <label>your cv</label>                                         <input required type="file" accept="application/msword" class="form-control" name="cv" id="cv" aria-describedby="name" placeholder="select cv file"/>                                     </div> 

i've got answer. here's code (isdoc own function):

    function onchange(event) {          var file = $('#file_cv')[0].files[0];          if ( !isdoc(file.name) ) {             alert("please, choose .doc or .docx type.");             document.getelementbyid("file_cv").value=""; } } 

now, it's impossible submit form without sending proper file.


Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -