I have a <input type="file" id="uploadPicture" value="123">
When I'm using: alert($("#uploadPicture").val());
It alerts an empty dialog.
The only way to set the value of a file input is by the user to select a file. This is done for security reasons. Otherwise you would be able to create a JavaScript that automatically uploads a specific file from the client's computer.
The input element, having the "file" value in its type attribute, represents a control to select a list of one or more files to be uploaded to the server. When the form is submitted, the selected files are uploaded to the server, along with their name and type.
The <input type="file"> defines a file-select field and a "Browse" button for file uploads. To define a file-select field that allows multiple files to be selected, add the multiple attribute.
You can give the input element a font opacity of 0. This will hide the text field without hiding the 'Choose Files' button.
@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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With