GJay
06-08-2006, 04:41 PM
I have a table, with a number of rows. At the end of each row, in a cell, is a checkbox that is used to 'select' a row.
I have a button that, when clicked, iterates through the checkboxes and copies the selected table-rows and 'pastes' them at the bottom of the table.
The table-rows contain form-elements, that want to be cloned exactly, except for one that needs to increase in value.
I have most of this working, except that select elements, when cloned, don't seem to recognise that they have been changed. e.g. if, after the page has loaded, I change the value of a select, then when the row is copied, the copy has the original value selected.
The (I think...) relevant code (there are a couple of prototype.js bits, but they should be self-explanatory...):
function copySelected() {
var boxes=document.getElementsByClassName('copyrow','gridform');
var newid=count;
var checkedboxes = new Array();
var els=$('gridform').getElementsByTagName('tbody')[0].getElementsByTagName('tr');
boxes.each(function(box) {
if(box.checked) {
var oldrow=box.parentNode.parentNode;
var clonerow=oldrow.cloneNode(true);
clonerow.id='row'+newid;
clonerow.hide();
clonerow.getElementsByTagName('input')[0].value=newid;
$('gridform').getElementsByTagName('tbody')[0].appendChild(clonerow);
var newrow=$('row'+newid);
box.checked=false;
Effect.Appear(newrow);
newid++;
}
});
count+=100;
}
I have a button that, when clicked, iterates through the checkboxes and copies the selected table-rows and 'pastes' them at the bottom of the table.
The table-rows contain form-elements, that want to be cloned exactly, except for one that needs to increase in value.
I have most of this working, except that select elements, when cloned, don't seem to recognise that they have been changed. e.g. if, after the page has loaded, I change the value of a select, then when the row is copied, the copy has the original value selected.
The (I think...) relevant code (there are a couple of prototype.js bits, but they should be self-explanatory...):
function copySelected() {
var boxes=document.getElementsByClassName('copyrow','gridform');
var newid=count;
var checkedboxes = new Array();
var els=$('gridform').getElementsByTagName('tbody')[0].getElementsByTagName('tr');
boxes.each(function(box) {
if(box.checked) {
var oldrow=box.parentNode.parentNode;
var clonerow=oldrow.cloneNode(true);
clonerow.id='row'+newid;
clonerow.hide();
clonerow.getElementsByTagName('input')[0].value=newid;
$('gridform').getElementsByTagName('tbody')[0].appendChild(clonerow);
var newrow=$('row'+newid);
box.checked=false;
Effect.Appear(newrow);
newid++;
}
});
count+=100;
}