I am getting strange behaviour when trying to upload files, using jQuery multi-file plugin, from a dynamically loaded form.
I'm using Firefox 9.0.1/Mac
This is how I am trying to bind to the change event: I have tried blur as well (and click and...)
$('#newticketform').live('change',function (e){ //newticket form is the form in which my input type=file is contained
$('#my_file_element').MultiFile(); //my_file_element is the input type=file element
});
Should the binding be to the form or input field? I did try both without any difference in behaviour.
When using .on instead of .live the function above is not triggered at all.
I've managed to upload files before loading the form as dynamic content. When loading the form into my main page I have to, of course, bind the event in some way.
This is the what happens:
- 1st time: Nothing happens (but he function above is triggered, confirmed using alert). I.e. no file is attached to the lista of files to be uploaded.
- 2nd time: The file is added to the list.
It seems like the binding is not realised before the first time I try to add a file and the second time it's working.
Just in case I'm including the html as well:
<form method="post" enctype="multipart/form-data" id="newticketform">
<input type="hidden" value="2000000" name="MAX_FILE_SIZE">
<label for="title">Rubrik</label> <input type="text" name="title" id="title"><br><br>
<label for="description">Beskrivning</label> <textarea name="description" id="description" cols="50" rows="15"></textarea><br>
<input type="file" maxlength="5" name="file[]" id="my_file_element" class="multi">
<div id="files_list"></div>
<input type="submit" value="Upload" name="upload">
</form>
Tested this after feedback from Jasper below:
$("#newticketmenu").live('click',function(event){
$("#adminarea").load("http://" + hostname + "/" + compdir + "/modules/core/newticket/newticket.php", function(){
$('#newticketform').on('change', '#my_file_element', function (){
$(this).MultiFile();
})
addNewTicketValidation();
});
});
Still, exactly the same behaviour.
All JavaScript files are loaded together with the main page.
What am I doing wrong? Is my way of binding incorrect?
Thanks!