I have a problem with <input type="file">
. I open the file selector and choose an image. I also have an <img>
element, of which I want the src
to be set to the chosen image. How can I do this using javascript (jQuery is fine)? The only thing I could find is that I am unable to get the path to the image; the value of the input will be C:/fakepath/myimage.fileextension
. Any ideas on how to do this? Thanks!
Asked
Active
Viewed 33 times
0

vrugtehagel
- 1,009
- 1
- 9
- 20
-
2You need JavaScript [FileReader API](https://developer.mozilla.org/en-US/docs/Web/API/FileReader) – Rahil Wazir Jul 27 '14 at 18:34
-
Related: http://stackoverflow.com/questions/23025414/attach-files-to-mandrill-message-with-browse-button – AstroCB Jul 27 '14 at 18:36
-
@AstroCB the related question says a server is required... What I want to do is part of a chrome extension (.crx) for a New Tab Page. This is as far as I know all local files, does this mean it's impossible? – vrugtehagel Jul 27 '14 at 18:41
-
@vrugtehagel See the question that I've marked this as a possible duplicate of: it should have your answer. – AstroCB Jul 27 '14 at 18:42
-
google for a preview script – Dev Man Jul 27 '14 at 18:53