Reputation: 427
I want to create a upload form. When I browse a file.Example. C:\mypicture\winter.jpg I want to get file name and fill in the text box 'winter.jpg' Automatically.
Thank .
Upvotes: 0
Views: 1034
Reputation: 72729
See the demo in pure JS: http://jsfiddle.net/VaWDP/2/
<input type="file" id="file">
<input type="text" id="name">
var input = document.getElementById('file');
var name = document.getElementById('name');
if (input.addEventListener) {
input.addEventListener('change', add_filename);
} else if (input.attachEvent) {
input.attachEvent('onchange', add_filename);
}
function add_filename()
{
name.value = input.value.split(/\\|\//).pop();
}
See the demo in jQuery: http://jsfiddle.net/SsW6t/
(function() {
$('#file').change(function() {
$('#name').val($(this).val().split(/\\|\//).pop());
});
})(jQuery);
Upvotes: 2
Reputation: 20201
It's not possible. Websites should not be able to predetermine location of a data on your local disk.
If such thing would be possible some questions arise like:
@PeeHaa
commented that it is and therefore if such example exists it's clearly a security issue. This JSFiddle example does not work for me...
Upvotes: 0