Hey guys,

Currently working on a app through django where several files can be uploaded. Now i've used the snippet found under, to dynamically add new forms.

Link to snippet: http://stackoverflow.com/questions/5...mset-with-ajax

The problem i have is that i have no idea how to make a function for deleting the extra rows generated by the javascript in such a way that the user can delete and add forms at will.

Any help regarding this would be deeply appreciated.

JS code:
Code:
function cloneMore(selector, type) {
    var newElement = $(selector).clone(true);
    var total = $('#id_' + type + '-TOTAL_FORMS').val();
    newElement.find(':input').each(function() {
        var name = $(this).attr('name').replace('-' + (total-1) + '-','-' + total + '-');
        var id = 'id_' + name;
        $(this).attr({'name': name, 'id': id}).val('').removeAttr('checked');
    });
    newElement.find('label').each(function() {
        var newFor = $(this).attr('for').replace('-' + (total-1) + '-','-' + total + '-');
        $(this).attr('for', newFor);
    });
    total++;
    $('#id_' + type + '-TOTAL_FORMS').val(total);
    $(selector).after(newElement);
}
Template code:

HTML Code:
<div class="f_unify">
		<form class="simpleform" action="" method="post" enctype="multipart/form-data">
			{{ formsetFile.management_form }}
			{% for form in formsetFile.forms %}
                        <fieldset class="mainfieldset">
                        <legend class="outer">
                        <span class="legendtext">Check by URI</span>
                        
                        </legend>
                        <div class="singlerow">
                        
                        {% csrf_token %}
			{{ formURL.as_table }} 
                        
                        <span class="description">(<cite>http://www.egovmon.no/test.pdf</cite>)</span>
                        </div>
                        
                        <input type="submit" value="Check" />
                        </fieldset>
                        
			{% endfor %}
		</form>
                <form class="simpleform" action="" method="post" enctype="multipart/form-data">
			{{ formsetFile.management_form }}
			{% for form in formsetFile.forms %}
                        <fieldset class="mainfieldset">
                        <legend class="outer">
                        <span class="legendtext">Check by File Upload</span>
                        </legend>
                        <div class="singlerow">
			<div class="table">
			<table class='no_error'>		
			{% csrf_token %}
			{{ formsetFile.as_p }}
			</table>
                        </div>
                        
			</div>
                        <input type="button" value="Add +" id="add_more">
                        <input type="submit" value="Check" />
                        </fieldset>
			{% endfor %}
			<script>
				var maxRows = 10;
				var i = 1;
				$('#add_more').click(function() {
					if(i < maxRows) {
					cloneMore('div.table:last', 'service' + i++);
					}
					else {
						alert('You can only upload 10 files per instance')
						}
				})
                                
                                $("#delete").click(function(){
                                deleterow();
                                });
			</script>


		</form>
                
</div>