DGT
DGT

Reputation: 2654

empty C:\fakepath\.. file upload in IE

How do I remove the selection from the input type=file, when something is entered in the textarea. The following Jquery fails, because IE replaces the local drive and directory path to something like, C:\fakepath\file.txt.
Many thanks in advance.

$("textarea#txt_id").live('keyup', function(){
    $('input[type=file]').val('');
});

<textarea name="txt" id="txt_id" rows="8" cols="64"></textarea>

<input type="file" name="file" id="file_id" />

Upvotes: 0

Views: 4846

Answers (2)

Ernesto
Ernesto

Reputation: 11

Have a solution for you. First check if browser is IE, next use encodeURI to encode all the file path and name, you have to do that first in order to correctly capture the unescaped chars like "\". Then just replace, its working for me:

var browserName=navigator.appName; 
if (browserName=="Microsoft Internet Explorer")
{
    var soloNombre = encodeURI(soloNombre);
    soloNombre = soloNombre.replace("C:%5Cfakepath%5C","");
    var soloNombre = decodeURI(soloNombre);
    alert(soloNombre);
}

Works like a charm.

Upvotes: 1

Teja Kantamneni
Teja Kantamneni

Reputation: 17492

Replacing the file control with the same html will clear it

$('#fileId').html($('#fileId').html());

Or using just java script...

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

Upvotes: 2

Related Questions