Reset a File Input

Y

YoBro

Hi,

Is this possible, if so how would you go about it.

I have a reasonably large form that includes 6 file input fields.
I wanted to create an option to allow the user to reset only the file input
fields. Currently if they select an image to upload and realise it is the
wrong one there is no way of resetting it. Except of course, manually
deleting the text out of the field.

Because you cannot reference and change the value of a file input, I cannot
set the value to "".

Is there any other way to add a rest button but specify the fields that you
want to reset. I do not want to rest the entire form.

Many thanks.

YoBro
 
J

Joakim Braun

YoBro said:
Hi,

Is this possible, if so how would you go about it.

I have a reasonably large form that includes 6 file input fields.
I wanted to create an option to allow the user to reset only the file input
fields. Currently if they select an image to upload and realise it is the
wrong one there is no way of resetting it. Except of course, manually
deleting the text out of the field.

Because you cannot reference and change the value of a file input, I cannot
set the value to "".

Is there any other way to add a rest button but specify the fields that you
want to reset. I do not want to rest the entire form.

Many thanks.

YoBro

I hope someone has a brighter idea than this: Save all form element values
except the file inputs, reset the form, then set all form element values
except the file inputs back to the corresponding saved values.

Joakim Braun
 
P

PDannyD

YoBro said:
Hi,

Is this possible, if so how would you go about it.

I have a reasonably large form that includes 6 file input fields.
I wanted to create an option to allow the user to reset only the file
input fields. Currently if they select an image to upload and realise
it is the wrong one there is no way of resetting it. Except of
course, manually deleting the text out of the field.

Because you cannot reference and change the value of a file input, I
cannot set the value to "".

Is there any other way to add a rest button but specify the fields
that you want to reset. I do not want to rest the entire form.

Use two forms?
 
I

Ian Sedwell

Use two forms?


I didn't know you couldn't mess with the value of a file input field. Never
had to try! But it makes sense that that is so from a security point of
view. Ah well, live and learn, eh.

I think what I'd do, is save the field values I wanted to keep into cookies
or global variables, reset the form and then restore the retained values to
their original fields from their temporary containers.

Maybe there's a more elegant way.

Cheers

Ian
 
Y

YoBro

Hmmm,

It is a really complicated form already, and massive, but quite a bit of
DHTML for different aspects of it. It is used specifically in Internet
Explorer, and is part of a companies Intranet. So I don't need anything
cross browser compatible, but I was hoping for an easy fix.

I thought about the cookie, idea but it is alot of work. I might have to
head down that road. It is a shame the reset button cannot have specified
values. This way you could click reset and specify which fields you want to
reset.

Thanks for the feedback!
 
J

J. J. Cale

YoBro said:
Hi,

Is this possible, if so how would you go about it.

I have a reasonably large form that includes 6 file input fields.
I wanted to create an option to allow the user to reset only the file input
fields. Currently if they select an image to upload and realise it is the
wrong one there is no way of resetting it. Except of course, manually
deleting the text out of the field.

Because you cannot reference and change the value of a file input, I cannot
set the value to "".
document.forms['yourFormName'].yourFileInputName.value="";
Is there any other way to add a rest button but specify the fields that you
want to reset. I do not want to rest the entire form.
<form name='yourFormName' onsubmit='yourFunction()>
<input type="file" name="yourFileInputName">
</form>
<script type=text/javascript>
function yourFunction() {
// validate what you want here;
// change form field value as necessary (see above comment)
if(!confirm("Ok to submit or whatever") return;
}
 
G

G Roydor

YoBro a écrit:
Hi,

Is this possible, if so how would you go about it.

I have a reasonably large form that includes 6 file input fields.
I wanted to create an option to allow the user to reset only the file input
fields. Currently if they select an image to upload and realise it is the
wrong one there is no way of resetting it. Except of course, manually
deleting the text out of the field.

essayez avec 6 forms plus une qui récapitule
et soumettez par la methode submit après avoir collationné les fichiers
valides

test with 6 forms more one which recapitulates and submit by the method
..submit() after having collated the valid files

GR
 
P

Philip Ronan

Hmmm,

It is a really complicated form already, and massive, but quite a bit of
DHTML for different aspects of it. It is used specifically in Internet
Explorer, and is part of a companies Intranet. So I don't need anything
cross browser compatible, but I was hoping for an easy fix.

Associate each file input field with a checkbox that toggles the field's
'disabled' flag. (Disabled fields are always unsuccessful, so their contents
should be ignored.)
 
Y

YoBro

Hi,

You cannot change a file input field with JavaScript (for security reasons).
So this method won't work.

YoBro


J. J. Cale said:
YoBro said:
Hi,

Is this possible, if so how would you go about it.

I have a reasonably large form that includes 6 file input fields.
I wanted to create an option to allow the user to reset only the file input
fields. Currently if they select an image to upload and realise it is the
wrong one there is no way of resetting it. Except of course, manually
deleting the text out of the field.

Because you cannot reference and change the value of a file input, I cannot
set the value to "".
document.forms['yourFormName'].yourFileInputName.value="";
Is there any other way to add a rest button but specify the fields that you
want to reset. I do not want to rest the entire form.
<form name='yourFormName' onsubmit='yourFunction()>
<input type="file" name="yourFileInputName">
</form>
<script type=text/javascript>
function yourFunction() {
// validate what you want here;
// change form field value as necessary (see above comment)
if(!confirm("Ok to submit or whatever") return;
}
Many thanks.

YoBro
 
Y

YoBro

Hi,

This was going to be my option, and have sort of implemented it, if they
re-use an image already on the server. It disables the file input so they
cannot upload an image as well as re-use an image.

YoBro
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top