By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,843 Members | 2,324 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,843 IT Pros & Developers. It's quick & easy.

how does one blank a file input in older versions of IE?

P: n/a

At a certain point in my code, I need to blank the value in a file
input. The situation comes up when a user first thinks they want to
upload something from their harddrive, but then they change their mind
and decide to choose a file from an online archive. I thought I could
get a reference to the input and then set value to blank, but that only
works in FireFox. For IE, I only got this to work by setting innerHTML
to blank:

if (document.getElementById &&
document.getElementById(idOfFileInputToBeMadeBlank )) {
var referenceToFileInput =
document.getElementById(idOfFileInputToBeMadeBlank );
referenceToFileInput.value = "";
referenceToFileInput.innerHTML = "";
}

However, this will probably break in old versions of IE. So what works
for older versions of IE?

Sep 11 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Jake Barnes said the following on 9/11/2006 4:38 PM:
At a certain point in my code, I need to blank the value in a file
input. The situation comes up when a user first thinks they want to
upload something from their harddrive, but then they change their mind
and decide to choose a file from an online archive. I thought I could
get a reference to the input and then set value to blank, but that only
works in FireFox. For IE, I only got this to work by setting innerHTML
to blank:

if (document.getElementById &&
document.getElementById(idOfFileInputToBeMadeBlank )) {
var referenceToFileInput =
document.getElementById(idOfFileInputToBeMadeBlank );
referenceToFileInput.value = "";
referenceToFileInput.innerHTML = "";
}

However, this will probably break in old versions of IE. So what works
for older versions of IE?
The same thing that will work in any browser that supports form
manipulation:

document.forms['formID'].reset();

Voila! Your file input is blank.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Sep 12 '06 #2

P: n/a

Randy Webb wrote:
if (document.getElementById &&
document.getElementById(idOfFileInputToBeMadeBlank )) {
var referenceToFileInput =
document.getElementById(idOfFileInputToBeMadeBlank );
referenceToFileInput.value = "";
referenceToFileInput.innerHTML = "";
}

However, this will probably break in old versions of IE. So what works
for older versions of IE?

The same thing that will work in any browser that supports form
manipulation:

document.forms['formID'].reset();

Voila! Your file input is blank.
I appreciate your answer, but it looks like it will blank the whole
form. It's important that the form keep its information, as the user
has input it, and instead we merely blank the one input.

Sep 12 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.