JQuery - starting a function after pressing the open button (from input = "file")

How can I run the function after clicking the Open * button?

HTML

<form id="xxx"> <input id="yyy" type="file" /> </form> 

Js

 $(function(){ $('body').append('jq works <br />'); $("#xxx").submit(function () { $('body').append('start function<br />'); }); }); 

jsfiddle http://jsfiddle.net/vGBaK/

edit: I mean this button → alt text

Thanks in advacen! Peter

+1
source share
2 answers

You can use the change event, it will not fire if the same file is selected, but if you also clear the click event, it should work.

see this jsfiddle

 $(function(){ $('body').append('jq works <br />'); $("#xxx").submit(function () { $('body').append('go >> <br />'); }); $("#yyy").change(function(){ alert("changed"); }).click(function(){ $(this).val("") }); }); 
+1
source

Here I assume that the open * button means the button for viewing your file entry window,

  $("#yyy").click(function(){ //alert("button clicked") // write your code }) 
0
source

All Articles