views:

80

answers:

1

I need to pass the filename of a file-input to a parent page... is this even possible?

The input type ="file" has a value, but can I use it like this?

I have used the value of the file-input to check the extension of the file, and it works! So I guess there is a value, but can this be done and is it reliable?

If not, how would you have done it?

Thanks

+3  A: 

You can only access the file name (without the full path) with javascript in all the browsers except IE.

var filename = document.forms.myForm.elements.myFileInput.value;

will give "file.gif" if the file c:\docs\bah\file.gif was selected

Fabien Ménager
Perfect answer, thanks man!!!
Camran
Indeed just the usual way. I would only add: You can *access* it, but not *edit* it. Keep it in mind.
BalusC
By the way, what would I do in IE then? is there a way around it?
Camran
In IE, you can access the full path ;)
Fabien Ménager
FYI You can get the full path in FF `<` v3.
Crescent Fresh