I get the input file element, and try to click on it in js on Chrome console, but it does not work and the file upload dialog does not appear. How can I achieve this?
document.getElementById("input_file").click();
Asked
Active
Viewed 1,353 times
1

Leslie Wu
- 760
- 3
- 13
- 29
-
Do you want to click by javascript or you want to capture the click? You want to do some action on clicking "input_file" ? – PC. May 10 '13 at 06:14
-
2You can't. It's a security feature: http://stackoverflow.com/questions/210643/in-javascript-can-i-make-a-click-event-fire-programmatically-for-a-file-input – Ahmed Nuaman May 10 '13 at 06:15
-
I want to click by javascript. @Pramod – Leslie Wu May 10 '13 at 07:47
-
Yes, there are many answers to your questions. You should have searched once in stackoverflow at least. http://stackoverflow.com/questions/5440832/generating-a-click-event-on-using-javascript or http://stackoverflow.com/questions/906486/how-can-i-programmatically-invoke-an-onclick-event-from-a-anchor-tag-while-kee – PC. May 11 '13 at 10:39
1 Answers
-2
try with onClick:
document.getElementById("input_file").onclick = function(){
//code for the action when clicked
};
Look here: http://jsfiddle.net/ghP2Y/1/

Daniel Garcia Sanchez
- 2,306
- 5
- 21
- 35