473,839 Members | 1,411 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Blank out a file field

Hi all,
I have the following codes,

<script language="JavaS cript">
function check_stuff(fie ld)
{
alert("blank out the field now");
field.value = "";
}
</script>

<form name="test_form ">
<input type="File" name="test_uplo ad" size="50">
<input type="Button"
onclick="check_ stuff(document. test_form.test_ upload)" value="Click Me">
</form>

What I am trying to do is, when the users click the button, it would
blank out the path in the test_upload field. The problem is, the
test_upload field does not get cleared out and it is not giving me an
error either. May I ask how can I clear out the file field?

Thanks in advance,
Monte
*** Sent via Developersdex http://www.developersdex.com ***
Jul 23 '05 #1
1 5555
Monte Chan wrote:
Hi all,
I have the following codes,

<script language="JavaS cript">
function check_stuff(fie ld)
{
alert("blank out the field now");
field.value = "";
}
</script>

<form name="test_form ">
<input type="File" name="test_uplo ad" size="50">
<input type="Button"
onclick="check_ stuff(document. test_form.test_ upload)" value="Click Me">
</form>

What I am trying to do is, when the users click the button, it would
blank out the path in the test_upload field. The problem is, the
test_upload field does not get cleared out and it is not giving me an
error either. May I ask how can I clear out the file field?


Javascript security prevents you from changing the value attribute of a
file input. If you knew (or guessed) the location of a file, you could
simply change the value of the input onsubmit and get the user to send
you any file you liked rather than the one they'd selected.

You can replace the input with a new one, which will have the same
effect as 'blanking' the current one. This is not optimal as you must
copy over the properties of the old input to the new one - if you clone
the node the new one will have the same unalterable file value as the
old one.

Below is a script that creates a new input, changes it's type, matches
the id and name of the old input (if it has them), then replaces the
old with the new. You may want to copy over other attributes too, say
className, style properties, etc.

<form action="">
<input type="file" name="fifo">
<input type="submit" value="Send file"><br>
<input type="button" value="Clear filename" style="width: 10.7em;"
onclick="
var z = this.form.fifo;
var x = document.create Element('input' );
x.type = 'file';
if (z.name) x.name = z.name;
if (z.id) x.id = z.id;
this.form.repla ceChild(x,z);
">
</form>


--
Rob
Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
3239
by: JDS | last post by:
Hi, all. I'd like to do the following, preferably *without* resorting to JavaScript: I have a long, dynamically-generated form questionnaire. Not all of the form fields are dynamically generated, though. I'd like to capture the NAME of every HTML form field element on the server, even if that element is submitted blank. The trouble is, with, say, radio buttons or checkboxes for example, a *blank* element does not get submitted at all.
2
3334
by: Ravi | last post by:
I have a webpage(with a text field and a button) which prompts for a local file and attempts to load the file in the window if the user clicks on the button. The javascript code onClick event uses the location.href property to achieve the desired result. (This loaded page has some additional functionality which lets them upload the contents to the server.) This approach only seem to work for some computers and on others it is loading a...
1
4292
by: Joel | last post by:
Hi, How do you determine if a Date field is blank. In my Sql statement I only want records who's date field is blank (i.e. checking for only open invoices where Date_Paid = '' ...still open ...it doesn't work when I use that syntax) Thank you
19
7026
by: Joe Scully | last post by:
Hi all, I am having trouble with access adding a blank record to a subform everytime I finish entering data and closing the form. (The form and subform are based on the one table) When entering data into the subform I get the pencil icon to show data addition, but underneath the record I am inputting data the record is blank with a star(*)icon and this is the record(blank)that always gets saved with all the records that actually have...
5
2457
by: ChadDiesel | last post by:
My basic question is why does my print report button on my subform print a blank report when my cursor is on a blank entry line? Here is a more detailed explanation of my problem. I have a form that contains shipment destination information and a subform that contains boxes for that shipment. The main form is a table called Ship_Info, and the subform is a table called Label_Info. They both contain and are linked by a field called...
2
3169
by: JohnR | last post by:
When creating an msAccess db within the Access UI itself the fields that are text are NOT padded with blanks. For example, if I have a 10 char field and put in "HI" and then when I come back to the field and click my mouse on it the cursor is just after the "I" in "HI"... that is, no blanks were added to the field. However, when I create an MDB database programatically in VB.Net using ADOX and create the tables using SQL stmts (ie:...
2
6230
by: JohnR | last post by:
When creating an msAccess db within the Access UI itself the fields that are text are NOT padded with blanks. For example, if I have a 10 char field and put in "HI" and then when I come back to the field and click my mouse on it the cursor is just after the "I" in "HI"... that is, no blanks were added to the field. However, when I create an MDB database programatically in VB.Net using ADOX and create the tables using SQL stmts (ie:...
0
2156
by: visionstate | last post by:
Hi there, I have a form which has 2 text boxes, a combo box and a sub form in it (which reads from a query. The query reads from the table). On load, I would like the fields in the text boxes and combo box to be become blank. If I use the "" or 'null' instruction then this in turn makes the corresponding field in the sub form blank which in turn makes the query field blank and the table field blank! If I then change the combo box option,...
4
2221
by: sparks | last post by:
I am trying to fix a database that someone did about 4 yrs ago in access97. The main table just contains demographics and is on the main form of the database. It has a subform on a tab that contains the other information. it is set 1 to 1 in the relationships. simplify if I can
0
9856
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10914
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10656
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10299
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9434
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7022
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5684
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5872
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4071
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.