0

I think I have two questions. The second question is based on the first one.

First, I want to know about using js to detect click action. Assume I have a button selectImage, which is used to upload local image picture, i.e. after click the selectImage button, one file open dialog will pop up to let me choose the uploading file.

My question is: if we use js listener to listen to the click action of selectImage, when we click the it and file open dialog popped up, could we be noticed that the click action happened?

My second question is: if we can't detect the click action happen, which may be due to the process of choosing uploading file didn't finish, is there one way in js to detect the success of this click action?

Thank you very much.

Terence Xie
  • 185
  • 2
  • 16

2 Answers2

1

You can call a function on clicking the file input button as

 <input type="file" onclick="myFunction()" />

And the make a function in javascript as

function myFunction(){
  alert('click action happened');
}

Check snippet

function myFunction(){
  alert('click action happened');
}
<input type="file" onclick="myFunction()" />
0

Use addEventListener() to the get the click event of input

var file = document.getElementById("file")
file.addEventListener("click", function(){
    alert("Now select a file");
});
<input type="file" id="file" />
Munawir
  • 3,346
  • 9
  • 33
  • 51