Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am trying to select an image using an input tag from JavaScript, however I am getting undefined error. Please see my code below, I am getting error at input.files[0]

How can I select an image?

function loadImage(input)
{
var file = input.files[0];
var FileReader = new FileReader();
...

}


What I have tried:

Tried googling with no luck, usually input.files work fine
Posted
Comments
Richard MacCutchan 11-Jul-21 7:13am    
Which reference is undefined: input, input.files or input.files[0]? Use the debugger to find which one and why.
Faran Saleem 11-Jul-21 7:16am    
Unable to get proper of 0 of undefined or null reference.. This is the error I am getting.. so it is input.files[0]
Richard MacCutchan 11-Jul-21 8:40am    
That tells you that there are no entries in the files variable. Again, use your debugger to find out why. This is not something that anyone here can do for you.
Faran Saleem 11-Jul-21 8:50am    
It works fine on my local machine but on SIT server it does not
Richard MacCutchan 11-Jul-21 9:33am    
This is a common issue that people face, because they fail to understand how a website works. If the files are stored on the server then they cannot be accessed via Javascript in a live website. The Javascript code runs in the browser which is on the client system.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900