I have a <input type="file" id="uploadPicture" value="123">
When I'm using: alert($("#uploadPicture").val());
It alerts an empty dialog.
I have a <input type="file" id="uploadPicture" value="123">
When I'm using: alert($("#uploadPicture").val());
It alerts an empty dialog.
You can get it by using document.getElementById();
will give the value of file,but it gives with fakepath as follows
You can't set the
value
of afile
input in the markup, like you did withvalue="123"
.This example shows that it really works: http://jsfiddle.net/marcosfromero/7bUba/
You can read it, but you can't set it.
value="123"
will be ignored, so it won't have a value until you click on it and pick a file.Even then, the value will likely be mangled with something like
c:\fakepath\
to keep the details of the user's filesystem private.It's old question but just in case someone bump on this tread...
No need for regex, jQuery....
@BozidarS: FileAPI is supported quite well nowadays and provides a number of useful options.
That'll get you the file selected.
However, you can't set the value yourself.