I have a <select id='group1'>
drop down that populates a <textarea id='group2'>
using
$('#group1').on('change', function(event) {
$.post('get_data.php', {sent_id: form1.group1.value },
function(bounced) {
var valNew = bounced.split(',');
$('#group2').html(valNew[0]) ;
});
});
This part works ok. Now I am trying to clone this <div id='tableline_00'>
and assign new id
s to inputs using
var current_id = 0;
$('#btn').click(function(){
nextElement($('#tableline_00'));
})
function nextElement(element){
var newElement = element.clone(true);
var id = current_id+1;
current_id = id;
if(id <10)id = '0'+id;
newElement.attr('id',element.attr('id').split('_')[0]+'_'+id);
var field = $('input', newElement).attr('id');
$('input', newElement).attr('id', field.split('_')[0]+'_'+id );
newElement.appendTo($('#elements'));
newElement.slideDown('fast');
}
This works too but the $('#group1').on('change', function(event)
works just for the first line because all the new clone lines have new input names. How could you change $('#group1')
and $('#group2')
to be variable. I am new to jQuery so any help/link is useful... maybe different approach?