2

i used file control in a html page i want to remove the file location from control when user click on reset button.

$("#control").val("");

if i run this code he not work in Chrome but in Firefox

what i do to unselect the file who is not selected in file upload control.

how i can reset the controls without reset the whole form. are any thing exist to do this.

  • Have a look at the top answer to a similar question, here: http://stackoverflow.com/questions/1043957/clearing-input-typefile-using-jquery – Mike Nov 12 '10 at 11:50

4 Answers4

5

The other solution didn't work me. I used the following code and it worked for me.

$("#control").val(null);
ksg91
  • 1,279
  • 14
  • 34
3

According to this article, you can use the following JavaScript method to clear the HTML input file control's value:

function clearFileInputField(tagId) {
    document.getElementById(tagId).innerHTML = 
                    document.getElementById(tagId).innerHTML;
}

Or, if refactored in jQuery, this should work as well:

$("#control").html($("#control").html());
Prutswonder
  • 9,894
  • 3
  • 27
  • 39
0

Try this JS code without any external library:

var file = document.getElementById("file1");
    file.value = file.defaultValue;
Hassan Ali Shahzad
  • 2,439
  • 29
  • 32
-1

If you using jQuery then following also can be utilize.

$('"#control"').prop('value', '');
Pranav Bhatt
  • 715
  • 4
  • 8