views:

40

answers:

1

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" />
+2  A: 

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;
}
Teja Kantamneni
See the closing `/>` of an `<input />` tag? They don't have inner html.
Roatin Marth
I tried. Doesn't work for IE.
DGT