I have a <input type="file" id="uploadPicture" value="123">
When I'm using: alert($("#uploadPicture").val());
It alerts an empty dialog.
This question is related to
javascript
jquery
file
input
You can't set the value
of a file
input in the markup, like you did with value="123"
.
This example shows that it really works: http://jsfiddle.net/marcosfromero/7bUba/
You can get it by using document.getElementById();
var fileVal=document.getElementById("some Id");
alert(fileVal.value);
will give the value of file,but it gives with fakepath as follows
c:\fakepath\filename
Solution
document.getElementById("uploadPicture").attributes.value.textContent
@BozidarS: FileAPI is supported quite well nowadays and provides a number of useful options.
var file = document.forms['formName']['inputName'].files[0];
//file.name == "photo.png"
//file.type == "image/png"
//file.size == 300821
It's old question but just in case someone bump on this tread...
var input = document.getElementById("your_input");
var file = input.value.split("\\");
var fileName = file[file.length-1];
No need for regex, jQuery....
don't give this in file input value="123".
$(document).ready(function(){
var img = $('#uploadPicture').val();
});
$('input[type=file]').val()
That'll get you the file selected.
However, you can't set the value yourself.
Source: Stackoverflow.com