DOM Documentation (Mozilla):
element = document.getElementById(id);
Where
element is a reference to an Element or null if the element with the specified identifier is not in the document.id is a string string representing the unique identifier of the item being searched.
In your code, document.getElementById(id) returns one element, not a list.
To access the files added to the input, check out the HTML5 file API.
var f = (document.getElementById('img').files); for (var i =0; i < f.length; i++){ var new_div = document.createElement('div'); new_div.innerHTML = f[i].name; document.body.appendChild(new_div); }
FYI: Using document.write() extremely dangerous and should be avoided. To learn more about this stackoverflow method. Q & A: Why is document.write considered "bad practice"?
In the above example, I replaced document.write with document.body.appendChild
Fiddle (with jQuery) : http://jsfiddle.net/4Yq4F/
Getting the full path to the file
This is the answer in your request for the full file path. Unfortunately, due to security concerns, this is not at the moment. However, Mozilla Firefox will provide you with the full path to the file with the mozFullPath attribute. If you want to use it, in the example above replace f[i].name with f[i].mozFullPath
source share