Is it possible to clear an <input type='file' />
control value with jQuery? I've tried the following:
$('#control').attr({ value: '' });
But it's not working.
Is it possible to clear an <input type='file' />
control value with jQuery? I've tried the following:
$('#control').attr({ value: '' });
But it's not working.
For obvious security reasons you can't set the value of a file input, even to an empty string.
All you have to do is reset the form where the field or if you only want to reset the file input of a form containing other fields, use this:
Here is an exemple: http://jsfiddle.net/v2SZJ/1/
This works with Chrome, FF, and Safari
May not work with IE or Opera
It's easy lol (works in all browsers [except opera]):
JS Fiddle: http://jsfiddle.net/cw84x/1/
In IE8 they made the File Upload field read-only for security. See the IE team blog post:
$("#control").val('')
is all you need! Tested on Chrome using JQuery 1.11Other users have tested in Firefox as well.