473,287 Members | 1,865 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,287 software developers and data experts.

Blank out a file field

Hi all,
I have the following codes,

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

<form name="test_form">
<input type="File" name="test_upload" size="50">
<input type="Button"
onclick="check_stuff(document.test_form.test_uploa d)" 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 5529
Monte Chan wrote:
Hi all,
I have the following codes,

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

<form name="test_form">
<input type="File" name="test_upload" size="50">
<input type="Button"
onclick="check_stuff(document.test_form.test_uploa d)" 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.createElement('input');
x.type = 'file';
if (z.name) x.name = z.name;
if (z.id) x.id = z.id;
this.form.replaceChild(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
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...
2
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...
1
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...
19
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...
5
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...
2
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...
2
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...
0
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...
4
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...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.