jquery - Uploading a file using hidden input field -
i'm trying call upload file function href link , though browse box being displayed, can't run validation on selected file. here code have:
<a href="#" onclick="$('input[id=formmedia]').click();"><div class="sidebarsectionlink">click here add files</div></a> //calls browse box <input type="file" id="formmedia" style="display: none;"> //hidden input //post photo jquery $('#formmedia').blur(function() { var pic=$("#formmedia").val(); if(pic.length < 1){ $('.sidebarsectionlink').html("please add photo").removeclass("success").addclass("error"); picok = 2; } else if(pic.indexof('jpg') === -1 && pic.indexof('jpeg') === -1 && pic.indexof('png') === -1 && pic.indexof('gif') === -1){ $('.sidebarsectionlink').html("invalid file format").removeclass("success").addclass("error"); picok = 2; } else { picok = 1; } });
document.getelementbyid('formmedia').onchange = uploadonchange; function uploadonchange(){ //validation here }
or jquery version
$('#formmedia').change(function(){ //validation });
because field hidden, onblur won't fire, changes can happen on hidden items.
Comments
Post a Comment