Limit the file inputs cloned in a form with Jquery

Posted by Philip on Stack Overflow See other posts from Stack Overflow or by Philip
Published on 2010-12-28T08:14:04Z Indexed on 2010/12/28 8:54 UTC
Read the original article Hit count: 416

Filed under:
|
|
|
|

Hi, i use this Jquery function to clone the file input fields in my form,

$(function() {
    var scntDiv = $('#clone');
    var i = $('#clone p').size() + 1;

    $('#addImg').live('click', function() {
            $('<p><label for="attach"><input type="file" name="attachment_'+ i +'"  /> <a href="#" id="remImg">Remove</a></label></p>').appendTo(scntDiv);
            i++;
            return false;
    });

    $('#remImg').live('click', function() {
            if( i > 2 ) {
                    $(this).parents('p').remove();
                    i--;
            }
            return false;
    });
});

is it possible to limit the fields that can be cloned? lets say a number of 4 fields?

thanks a lot,
Philip

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about forms