views:

129

answers:

3

I want to clear the file input in my form.

I know about setting the sources to the same method... But that method wont erase the selected file path.

Is there a way to clear the path inside the file input?

NOTE: I dont want to reload the page, or reset the form...

NO AJAX...

So, impossible?

Thanks

+1  A: 

JavaScript is not allowed to affect the contents of a file input field for security reasons. When it comes to files, if you need anything more robust than the most basic functionality the browser provides, you need to look at something like Flash or Silverlight.

Rex M
A: 
document.getElementById('your_input_id').value=''

Edit:
This one doesn't work in IE and opera, but seems to work for firefox, safari and chrome.

Soufiane Hassou
This works for me, although I always ask myself for how long.
Pekka
this wont work, just in some browsers, and also setting the value of a file input is a security breach... not good choice.
Camran
This doesn't work in IE (I don't think Opera either).
Roatin Marth
Thanks, I'll edit the answer.
Soufiane Hassou
+2  A: 

How about removing that node, creating a new one with the same name?

DFectuoso
how do you mean, give me an example please.
Camran