I'm doing a websystem where I need to add some inputs fields dynamically, doing click in a button and calling a jquery or javascript function... I could duplicate almost the whole form. but the upload fields.
I have two differents uploads, in the form.
This is the javascript for the "add one more record" function.
$('#add2').click(function() { idback=''; idback2=''; var source = $('#readroot:first'); clone = source.clone(true,true); clone.find(':input').attr('id', function(i, val) { return val + '_' + count; }); clone.find(':input').attr('name', function(i, val) { return val + '_' + count; }); clone.find(':input').attr('rel', function(i, val) { return val + '_' + count; }); clone.find('#removeme'+ '_' + count).attr('style','display: block'); clone.find("#field_idopciones_encuestas_chosen").attr('id', function(i, val) { idback='#'+val+'_'+count; return val + '_' + count; }); clone.find("#field-tipo_respuesta").attr('id', function(i, val) { idback2='#'+val+'_'+count; }); clone.find(':input').attr('class', function(i, val) { return val + '_' + count; }); clone.insertBefore(this); clone.attr('style', 'display: block'); $(idback).remove(); $('#field-idopciones_encuestas_' + count).attr('style','display: block'); $("#field-idopciones_encuestas_"+count).chosen({width:"80%"}); $(idback2).val(1); count++; });
This don't work with the uploads buttons. This buttons are created with some divs, spans and other elements all related with differents numbers. Can somebody help to clone this uploads fields? what attributes must find and change? or is there another way?
Thanks in advanced!