-4

I have an input that accepts a file to be uploaded. The problem is that I can not figure out how to call the function after the file is added to the input.

I have tried things like onMouseMove, onClick and onChange but they do not call the function after the file is added to the input.

jQuery('.attachment').click(function(){
  console.log("test");
  checkFile();
});
Grady D
  • 1,889
  • 6
  • 30
  • 61
  • doesnt `oninput` work? – Isaac Dec 17 '14 at 20:45
  • 2
    Please be more specific, post the code that doesn't work. Here's a minimal demo that works fine: http://jsfiddle.net/dg1hmLq3/ – pawel Dec 17 '14 at 20:48
  • @pawel That solved my issue! I was using `jQuery('.attachment').click()`. I changed this to `on('change')` and it is not working. If you post an answer I will accept it. – Grady D Dec 17 '14 at 20:51

2 Answers2

0

Add an "Add" or "Upload" button with your function in the onclick attribute.

<input type='submit' id='submit' name='submit' value='Upload' onclick='myUploadFunction()' />

mbomb007
  • 3,788
  • 3
  • 39
  • 68
0

HTML input file selection event not firing upon selecting the same file

Set the value of your element to null on every click. Then you get a onchange event fired if a file gets selected.

    input.onclick = function(){
        this.value = null;
        }
    input.onchange = function(){
        alert(this.value);
    }
Community
  • 1
  • 1
Scarysize
  • 4,131
  • 25
  • 37