Jquery File Type Input .change() Behaviour

Tagged:  

Jquery .change() function is commonly used in detecting the event on any change of the input. However, when you are handling the file type input, the .change() may not work as you expected.


$("input[name=fileTypeInput]").change(function(){  
        //do something
 });

In the above code, the file type input is work for the first time only (from blank to first selection of file), if you further change your input by selecting other files, it just wont work. This is probably due to jquery treat the file type input differently with the normal text input or other reason that I dont know.

To make the .change() works as you expected, everytime you choose the file, then do somethings. I will make use of the first time behaviour. Here is the solution,
1. Enclose the input with a div with an ID
2. Every time you change the file type input (choose the file), empty the div and fill with a new file input with the same name.
3. Bind the .change() function again on the new file type input


$("input[name=fileTypeInput]").change(function(){  
        myClickUpload();
 });
 function myClickUpload(){
       //do somethings
        $("#enclose_input_div").html("< input type='file'  name='fileTypeInput' class='input' size='1' />");
        $("input[name=fileTypeInput]").change(function(){  
           myClickUpload();
        });
 }

the movie the wild bunch with marlon brando carver celeberity movie archieve http://moviestrawberry.com/films/film_touched/ dinner and a movie
running scared wheelchair movie 2006 courage under fire movie guide london http://moviestrawberry.com/films/film_a_cinderella_story/ porn movie samples
iowa city movie schedule standoff step up movie soundtrack
movie theatres in lansing michigan basic gettysburg movie theaters http://moviestrawberry.com/films/film_death_of_a_president/ free hardcore fucking movie galleries
elvis movie jerard the crow stairway to heaven regal movie times http://moviestrawberry.com/films/film_fear_and_loathing_in_las_vegas/ christopher reeves in the lion and the lamb movie