Jquery: how to call the function again?
- by bakazero
I'm making the script for easy upload many files. I've tried fyneworks plugin, but the file name does not appear in a form that uses tiny_mce. This is the code:
$("document").ready(function () {
var i = 0; //iteration for Inputted File
var max = 5; //max file uploaded
createStatus(); //generate status container
$('.imageNow').change(function() {
if($(this).val()) {
var ext = $(this).val().split('.').pop().toLowerCase();
var allow = [ 'gif', 'png', 'jpg', 'jpeg' ];
if (jQuery.inArray(ext, allow) != -1) { //validation true
addImgInput($(this).clone());
$(this).addClass('imgOK');
$(this).removeClass('imageNow');
addImgList($(this).val());
removeImgStatus();
i++;
}
else {
addImgStatus();
$(this).remove();
addImgInput();
}
}
return false;
});
});
This is another function that I use:
function addImgInput(inputClone) {
$(inputClone).prependTo( $('#upload_images') ); //div container for generated InputFileImg
};
function addImgList(listingImg) {
$('#list_image_file').append('<li>' + listingImg + '</li>' ); //list all images that have been inputted
}
function createStatus() {
$('#upload_images').append('<small class="status"></small>'); //error display container
}
function addImgStatus() {
$('.status').append('* Wrong File Extension'); //error display text
}
function removeImgStatus() {
$('.status').empty();
}
Mmm..yeah is't not finished yet, because when I try to generate another Inputfile with imageNow class, the $('.imageNow').change(function() is not going to work anymore. Does anyone can help me? Thanks