473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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


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
2 1369
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

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Martin | last post by:
I don't know if this is a PHP problem or a MySQL problem - hopefully, someone here can give me a clue. I am getting the subject error when I try to connect to MySQL from a PHP page. $conn =...
7
by: Martin | last post by:
Again drawing on the groups experience:- 1. For general file opening and file saving, using VB6, are there any issues with using the FileOpen and FileSave Common Dialog Boxes? 2. Is using the...
6
by: Ruben | last post by:
Hello. I am trying to read a small text file using the readline statement. I can only read the first 2 records from the file. It stops at the blank lines or at lines with only spaces. I have a...
1
by: juppie | last post by:
Hello, I'm writing visual XML editor. At the moment I need a DTD parser which will parse DTD (either standalone or internal to XML doc) and give me an access to underlying DTD in convenient...
1
by: Erik Cruz | last post by:
Hi. I know that different .net framework versions can live together, but can I install the newer .net framework 1.1 and after that install the older .net framework 1.0 version? Or do I need to...
1
by: jcwmtl | last post by:
Hello all I'm building a suite of free php applications to create virtual worlds. My problem is i can't get my file to refresh. Can this be done with javascript? I would like to have the display...
7
by: Craig | last post by:
Hi I am trying to debug a problem with some ASP pages when accessed via IIS on Windows 2003 Server SP1. In summary, the pages are structured as follows: Root page Page loaded via IMG SRC ...
8
by: JM | last post by:
I installed a webserver based on scientific linux 4.4 yesterday (not my idea, but my bosses) and after doing all updates (apt-get and yum) the version of PHP was 4.3.9. Current version (at least...
7
by: beachdog | last post by:
I'm using Visual Studio 2005/C# to build a web client. The web server is something I've written in a different framework, which does not support generating wsdl, so I have hand-built a wsdl file,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.