You cannot change the value of the file input type, as this will lead to a security vulnerability. Instead, just replace the file input with a new one. Instead of $('#file').val('') do the following:
$('#file').replaceWith('<input name="file" type="file" id="file"/>');
It would be even better to clone a copy of the original version and store it in memory. When you need to replace it, just use the cloned copy and clone it again. So something like this:
$(document).ready(function() { var empty_input = $('#file').clone(); $('#the-form').on('change', '#file', function(el) { $('#the-form').submit();
Please note that I am using the delegated version with jQuery.on () , so the event will still work on the new input immediately after replacing it.
source share