views:

78

answers:

1

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

+1  A: 

i didn't actually understand if this is your problem:

when I try to generate another Inputfile with imageNow class, the $('.imageNow').change(function() is not going to work anymore.

but to solve this one you have to use .live:

$('.imageNow').live('change', function() {
   // your code
});
j.
Agreed, live is required when you want events to be registered against elements added after the document.onready event.
TreeUK
Wow thanks! it's working...
bakazero