Unable to clear input type = file in javascript jquery

Possible duplicate:
Clearing <input type = 'file' /> using jQuery

This is my code:

 <input ID="fileUpload1" runat="server" type="file" style="width:275px; position:absolute; left:1px"/>

I tried some solutions:

$("input[type='file']").val('');
$('#DivfileUpload').replaceWith("<input class=VWButton ID=fileUpload1 runat=server type=file style=width:275px; position:absolute; left:1px/>");

and many others from the Internet, but fail.

+5
source share
3 answers

You cannot set the value of the input file for (obvious) security reasons.

If you want to clean it, you need to reset the form in which it is located.


, . ( , , / ASP runat=server, quote, (, )).

+9

.val('') (, IE) .

: reset :

$('form').trigger('reset');

(, HTML ):

$('#fileUpload1').replaceWith('<input id="fileUpload1" type="file" style="width:275px; position:absolute; left:1px"/>');

CSS, .

CSS:

#fileUpload1 {
    width: 275px;
    position: absolute;
    left: 1px;
}

JavaScript:

$('#fileUpload1').replaceWith('<input id="fileUpload1" type="file"/>');

, , , . , , . , . .;)

+7
$(function() { 
  $('#fileUpload1').val(''); 
});
-1
source

All Articles