I may be "barking up the wrong tree" here but... I have a form that I am building for a client to make icon requests. For each icon request, the user enters information via a number of input fields and select form widgets. Each request is with a table row.
It works fine but I want to be able to add a bit of code that allows the user to insert a table row (a request) automatically as needed. Otherwise I would have to create a certain number of rows.
I found a piece of jQuery code that works. I copied the form to an html page, modified it and linked the code. It worked great plus it incremented and renamed the form elements.
The problem is that I cannot get it to work with chronoforms. I placed the form code (w/o script tags) in the "Form JavaScript" box.
I thought perhaps that I'd try it in the extra code box but then could not figure out how to add "&task=extra".
I already have jQuery 1.4.4.min.js linked for other things btw.
Here is the jQuery code snippet I found
// add a row
jQuery.fn.addClone = function() {
return this.each(function() {
// get row for cloningg
var row = $(this).parents('tr');
var parent = {};
// use tbody or table parent
if ( $(row).parents('tbody').length>0) {
parent = $(row).parents('tbody');
} else {
parent = $(row).parents('table');
}
// inject clone
var copy = $(row).clone();
$(copy).addClass('sadey');
$(copy).addClass('isclone');
$(parent).append( copy );
// remove last td and replace with remove html
$('.sadey').children('td:last').remove();
$('.sadey').append('<td><img src="../../images/stories/PTC/APPROVED/remove16x16.png" alt="" " onclick="$(this).killClone()"></td>');
// increment all ids and names
var id = ($('.isclone').length + 1);
$('.sadey').find('*').each(function() {
var tempId = $(this).attr('id');
if (typeof tempId != 'undefined' && tempId!='') {
$(this).attr('id',tempId + '_' + id);
}
var tempName = $(this).attr('name');
if (typeof tempName != 'undefined' && tempName!='') {
$(this).attr('name',tempName + '_' + id);
}
});
// remove active tag
$('.sadey').removeClass('sadey');
});
};
// remove a row and re-index the clones
jQuery.fn.killClone = function() {
var row = $(this).parents('tr');
$(row).remove();
// re-index
var id = 2;
$('.isclone').each(function() {
$(this).find('*').each(function() {
var tempId = $(this).attr('id');
if (typeof tempId != 'undefined' && tempId!='') {
tempId = tempId.split('_');
$(this).attr('id',tempId[0] + '_' + id);
}
var tempName = $(this).attr('name');
if (typeof tempName != 'undefined' && tempName!='') {
tempName = tempName.split('_');
$(this).attr('name',tempName[0] + '_' + id);
}
});
id++;
});
};
I make this call in the last cell in the "icon request row"
<td align="center"><img src="../../images/stories/PTC/APPROVED/add16x16.png" alt="" onClick="$(this).addClone();" /></td>
Thanks!