Html how to link to file in input tag
Suppose I have a simple form with a tag <input type="file">, what I want to do when the user selects a file, I would like to display this file (this is img) on the same page for viewing, the best user interface.
tried to set the value based on the onChange event, and then realized that this was not working.
any thoughts?
You do not need to upload an image before you can display it. Here is a jQuery snippet that will fit the trick:
$('input:file').change(function(){
var file = this.files[0];
var reader = new FileReader();
reader.onload = (function(event) {
$('#previewImage').attr('src',event.target.result);
});
reader.readAsDataURL(file);
});