+ 3
How to fire a javascript Event on file select?
So basically, i have ``` <input type="file" id="infile"> ``` And now I want to fire a javascript event when a file is choosed using it. I tried: ``` document.getElementById('infile').addEventListener('change', somefunc()); ``` But ```somefunc()``` is being executed ```onload```! Please help!!
3 Answers
+ 5
You need to get rid of the brackets after somefunc. E.g.
```
document.getElementById('infile').addEventListener('change', somefunc);
```
Because otherwise you are executing somefunc.
+ 4
Thanks Rowsej, It worked !!!
+ 4
No worries!